tags:

views:

20

answers:

1

Hello

Is there someway to render RouteLink as the name of the link aswell?

i.e

<%= Html.RouteLink(...., "myRoute", new { id = 75 }) %>

gets rendered as

<a href="http://foo/Something/75"&gt;http://foo/Something/75&lt;/a&gt;

Is there some neat trick för that?

/M

+2  A: 

You could create an extension method to handle it for you

public static string PrintRouteLink (this HtmlHelper helper, string routeName, int id)
{
    UrlHelper url = new UrlHelper(helper.ViewContext.RequestContext);
    return helper.RouteLink(url.RouteUrl(routeName,new { id =  id}),routeName,new { id =  id});
}

Then you can use:

<%= Html.PrintRouteLink(routeName,75) %>
Martijn Laarman