Generate links for routes with non-parameter url segments on ASP.NET MVC 2

Posted by spapaseit on Stack Overflow See other posts from Stack Overflow or by spapaseit
Published on 2010-05-07T23:20:17Z Indexed on 2010/05/07 23:28 UTC
Read the original article Hit count: 323

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about c#