RouteLink as linkname
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://fo开发者_高级运维o/Something/75">http://foo/Something/75</a>
Is there some neat trick för that?
/M
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) %>
精彩评论