Generate links for routes with non-parameter url segments on ASP.NET MVC 2
- by spapaseit
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'd rather use one of the provided helpers and 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.
I've even tried to render the link using plain ol' html
<a href="/suggestion/list/by/<%=Model.Tag %>"><%=Model.Tag %></a>
but this somehow didn't match the route either. There's probably a very simple solution and I might be over-complicating things in mi mind, but I'm at a loss.
Any ideas?
Thanks in advance.