How to configure ASP.NET MVC 3 routing so that it does not require the controller and action in the URL?
I have this to display the details for the element "abc123" configured with the default routing settings:
mysite.com/Home/Details/abc123
The value "abc123" is a unique value that the Home controller uses to find the correct item in the database.
But I would prefer to use these ultra-short URLs:
mysite.com/abc123
There will also be very few additional controllers on the site, such as O and Contact. I assume that I will also have to configure them specially, so the controller does not by default look for details for an element with the identifier “O” or “Contact”. How to do it?
UPDATE:
Here's what my routes ended up looking like:
routes.MapRoute("About", "About", New With {.controller = "About", .action = "Index"})
routes.MapRoute("ID", "{id}", New With {.controller = "Home", .action = "Details"})
routes.MapRoute("Default", "", New With {.controller = "Home", .action = "Index"})
:)
source
share