I’d like to maintain ASP.NET MVC 4’s existing controller/action/id routing with default controller = Home and default action = Index, but also enable controller/id to route to the controller’s index method as long as the second item is not a known action.
For example, given a controller Home with actions Index and Send:
/Home/Send -> controller's Send method
/Home -> controller's Index method
/Home/Send/xyz -> controller's Send method with id = xyz
/Home/abc -> controller's Index method with id = abc
However, if I define either route first, it hides the other one. How would I do this?
In case, that the list of your actions (e.g. Send) is well known, and their (action) names cannot be the same as some ID value, we can use our custom ConstraintImplementation:
And the route map (before the default one – both must be provided), should look like this:
Summary: In this case, we are evaluating the value of the “action” parameter.
NOTE:
actionnames andidvalues need to be unique… then this will work