I have a route defined with several hardcoded (non-parameter) segments:
routes.MapRoute(null, "suggestion/list/by/{tag}",
new { controller = "Suggestion", action = "List", tag = UrlParameter.Optional });
Suppose I’m in the Index view of SuggestionController, which has a Suggestion object for Model, how can I create a link that matches that route?
I know I can accomplish I by using plain ol’ html like:
<a href="/suggestion/list/by/<%=Model.Tag %>"><%=Model.Tag %></a>
But this makes it impossible to pass on other route parameters (as a RouteValueDictionary, for instance), doesn’t it?
I was actually wondering whether is would be possible to do using one of the provided helpers, but without naming the route. I’d prefer to keep the route name as null in order to avoid hard-coding to much on my views, but I can’t figure out how to user these non-parameter segments in Html.ActionLink or RouteLink methods.
Any ideas?
Thanks in advance.
The helper methods will take into account routes that you set up so you will be able to use them and they will output the URLs as you want. For example:
Or even better, if you are using the MVC futures assembly you will be able to do away with the magic strings and do:
EDIT: As Pointed out in the comments, there is a typo above, the calls to Action, should be ActionLink