Reputation: 89
I have an AppController and an AccountController. The AppController only has one view, index
, which takes query string parameters from the id
part of the url.
The default route is as follows: {controller}/{action}/{id}
This means for the query string parameters to work properly, the view name has to be in the url. url/view/id
I would like to hide that part of the url and render that view by default, so users need only go to url/id
.
I have tried {controller}/{id}
and {controller}/index/{id}
but neither work.
Upvotes: 0
Views: 125
Reputation: 1898
I think this would work. Set the url as : "{controller}/{id}"
and give it a default action parameter:
routes.MapRoute(
name: "Default",
url: "{controller}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Upvotes: 2