开发者

RouteLink as linkname

开发者 https://www.devze.com 2022-12-13 05:21 出处:网络
Is there someway to render RouteLink as the name of the link aswell? i.e <%= Html.RouteLink(...., \"myRoute\", new { id = 75 }) %>

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

精彩评论

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