ASP.NET Core生成超链接


引用自:

 

1、传统方式

  1. 第一种:@Html.ActionLink("Register", "Register", "Account")  
  2. 第二种:"@Url.Action("Register", "Account")">Register  

生成的Html代码

  1. 第一种:"/Account/Register">Register  
  2. 第二种:"/Account/Register">Register  

"/Product/Display/1">View Detailsa>  

4、通过路由名称指定

  1. routes.MapRoute(  
  2.     name: "login",  
  3.     template: "login",  
  4.     defaults: new { controller = "Account", action = "Login" });  

比如是上面这个路由

  1. <asp-route="login">Logina>  

通过asp-route指定就可以了

"https://aspecificdomain.com/Account/Register#fragment">Registera>  

6、如果你要指定网站当前的域名

  1. @Html.ActionLink("Register", "Register", "Account",  "https", null, null, null, null)  

7、asp.net core中新增的方法

  1. <asp-controller="Account"   
  2.    asp-action="Register"   
  3.    asp-protocol="https"   
  4.    asp-host="asepecificdomain.com"   
  5.    asp-fragment="fragment">Registera>  
  6.   
  7.   
  8. <asp-controller="Account"   
  9.    asp-action="Register"   
  10.    asp-protocol="https">Registera>