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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With