asp.net Core1.1版本生成超链接/a链接标签的方式

https://www.cnblogs.com/tangjiansheng/p/7116721.html

1、传统方式

 

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

 

生成的Html代码

 

  1. 第一种:<a href="/Account/Register">Register</a>  
  2. 第二种:<a href="/Account/Register">Register</a>  

 

 

2、asp.net core新增的方式

 

 

  1. <a asp-controller="Account" asp-action="Register">Register</a>  

注意:asp-controller为指定的控制器,asp-action为控制器中的方法,也就是Action

 

3、如果要指定参数的话

 

  1. <a asp-controller="Product" asp-action="Display" asp-route-id="@ViewBag.ProductId">View Details</a>  

asp-route-id为传递给Action的参数

 

生成的html代码

 

  1. <a href="/Product/Display/1">View Details</a>  

 

 

4、通过路由名称指定

 

 

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

比如是上面这个路由

 

 

  1. <a asp-route="login">Login</a>  

 

通过asp-route指定就可以了

5、通过http协议,IP或者域名指定

 

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

生成的链接

 

 

  1. <a href="https://aspecificdomain.com/Account/Register#fragment">Register</a>  

 

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

 

 

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

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

 

 

  1. <a asp-controller="Account"   
  2.    asp-action="Register"   
  3.    asp-protocol="https"   
  4.    asp-host="asepecificdomain.com"   
  5.    asp-fragment="fragment">Register</a>  
  6.   
  7. <!--或者使用下面的方法 -->  
  8. <a asp-controller="Account"   
  9.    asp-action="Register"   
  10.    asp-protocol="https">Register</a>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值