Is it possible to get Html.ActionLink() to render a link to a path that looks like this?
/posts/1/comments/2
In my app, I have this route:
context.MapRoute(
"CommentRoute",
"posts/{postId}/comments/{action}/{commentId}",
new {
controller = "Comments",
action = "details",
commentId = UrlParameter.Optional });
What overload/set of parameters can I send to Html.ActionLink to get a pretty path like the one above?
If this isn’t possible, is there a recommended implementation of a custom helper to achieve the same effect?
Html.ActionLinkwill look at your route table to generate the approriate link.You can call it as usual and it will use the correct URL: