Reputation: 379
How can I remove the Index from the MVC url that has a routeValue?
E.g. http://localhost/Beverage/Index/WhiteWine to http://localhost/Beverage/WhiteWine
but still be able to have http://localhost/Beverage/ShowBeverage/1
Upvotes: 10
Views: 4540
Reputation: 887877
You can create a custom route:
MapRoute("My Route Name",
"Beverage/{id}",
new { controller = "Beverage", action = "Index" });
Note that the controller name must be hard-coded in the route, then specified in the defaults to tell MVC which controller to use.
If you take the naive approach and map {controller}/{id}
, it will accept any URL of the form a/b
, which is not what you want.
Upvotes: 15