Skip to main content
 首页 » 编程设计

c#之获取 Html.RouteLink 结果的 URL 地址

2024年02月20日14dflying

结果

@Html.RouteLink("link-name" , "route-name" , new  
{ 
  id = "8850" , 
  title = "sample-title" , 
  description = "sample-description" 
} 
) 

是

<a href="/8850/sample-title/sample-description/">link-name</a> 

有没有只提供href地址的扩展方法?

请您参考如下方法:

您可以使用"Url.Action":

UrlHelper 类:

Action(string actionName, string controllerName, RouteValueDictionary routeValues); 

对于其他重载,检查这个:

UrlHelper.Action Method

例如。

<a href="@Url.Action(actionName, controllerName, routeValues)">link-name</a>