zoukankan      html  css  js  c++  java
  • asp.net Core1.1版本生成超链接/a链接标签的方式

    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. <asp-controller="Account" asp-action="Register">Register</a>  

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

    3、如果要指定参数的话

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

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

    生成的html代码

    1. <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. <asp-route="login">Login</a>  

    通过asp-route指定就可以了

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

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

    生成的链接

    1. <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. <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. <asp-controller="Account"   
    9.    asp-action="Register"   
    10.    asp-protocol="https">Register</a>  



    翻译原文(有删改):ASP.NET Core MVC Anchor Tag Helper

  • 相关阅读:
    选择学习Web前端开发的理由
    在Nginx下部署SSL证书并重定向至HTTPS
    使用pm2快速将项目部署到远程服务器
    DNS域名解析过程
    HTML5新特性总结
    基于 HTML5 Canvas 的智能安防 SCADA 巡逻模块
    react中使用css的7种方式
    原生JS实现滑动轮播图
    H5与企业微信jssdk集成
    img图片不存在显示默认图
  • 原文地址:https://www.cnblogs.com/tangjiansheng/p/7116721.html
Copyright © 2011-2022 走看看