Mvc 3 How to list all available routes?
How to do it:
@Html.ActionLink("MyText","Index","Home")
Translated to:
<a href="/Home">MyText</a>
If before printing
<a href="/Home/Index">MyText</a>
After I added the default action for the entire controller with:
routes.MapRoute( "DefaultActionToIndex", "{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional });
It seems to me that the helper method does more than print everything that was transmitted, but can resolve the route dictionary and find out that the "index" is not needed, since it was set as the default value.
The question is how?
Routing works in both directions, for incoming requests and generating URLs, it checks the routes in System.Web.Routing.RouteTable.Routes
(in order) with the provided values ββ(in this case { controller = "Home", action = "Index" }
) and uses the first route that matches. If the parameter has a default value and the supplied value is equal to this default value, it is not included in the URL.