开发者

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) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜