I have an action like so:
@Html.ActionLink(dinner.Title, "Details", new { id=dinner.DinnerID })
and a route defined like so:
routes.MapRoute(
"PrettyDetails",
"{Id}",
new { controller = "Dinners", action = "Details" },
new { Id = @"\d+" }
);
The action link renders <a href="/234">My Dinner</a>
Why does it not display "Details" in the link? Is it because it knows about the routes defined in Global.asax and therefore matches the pattern somehow?
Thanks
Because the route pattern you have defined in your Global.asax is
{Id}where id must be an integer. So to answer your question, yes, theHtml.ActionLinkhelper respects the routes you have defined in your Global.asax.If you want to be able to pass a different action than
detailsyou will have to modify your pattern. For example like this:{action}/{id}. Obviously the same stands true for the controller part.You could use the
Html.RouteLinkwhich allows you to specify a route name if you don’t want the evaluation to happen in the order of your route definitions in Global.asax. This way you could target a specific route. Of course the arguments you are passing must be coherent with this route.