0
votes

I'm Just starting to learn the asp.net mvc platform and I don't really like to have a /home/ in the url.

Is there any way possible to have a route with just action and id for the home controller where if there are 3 actions (index, about and contact) the url reads localhost:1190/ , localhost:1190/about and localhost:1190/contact.

I know I can make them into separate controllers and just have an index view for each but is that truly the best way of doing this?

1

1 Answers

3
votes

Sure:

routes.MapRoute(
    "Default",
    "{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

But bear in mind that since the controller name is no longer part of the route, you can no longer specify it -> you will always have one controller - Home, which could quickly become overbloated if you start putting all actions in a single controller.