簡體   English   中英

RouteLink作為鏈接名

[英]RouteLink as linkname

是否可以通過某種方式將RouteLink渲染為鏈接的名稱?

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

被渲染為

<a href="http://foo/Something/75">http://foo/Something/75</a>

有一些巧妙的技巧嗎?

/ M

您可以創建一個擴展方法來為您處理

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});
}

然后,您可以使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM