【问题标题】:Creating a custom anchor tag helper with hash string support创建具有哈希字符串支持的自定义锚标记助手
【发布时间】:2016-12-01 21:28:13
【问题描述】:

我正在尝试为支持 asp-hash 属性的 a 标记创建自定义 ASP.NET Core 标记帮助程序。该属性应该做的只是将提供的值附加到 href 属性的末尾。

<a asp-controller="Home" asp-action="Index" asp-hash="mainDiv">some link</a>

然后会生成:

<a href="http://localhost/home/index#mainDiv">some link</a>

我在asp.net github repo 的本节中找到了AnchorTagHelper 的源代码,但我找不到将内容附加到生成的href 末尾的方法

【问题讨论】:

    标签: c# asp.net-core asp.net-core-mvc tag-helpers


    【解决方案1】:

    不存在asp-hash 属性,但无需制作自定义锚标记助手。您正在寻找asp-fragment 属性:

    <a asp-controller="Home" asp-action="Index" asp-fragment="mainDiv">some link</a>
    

    【讨论】:

    • 愚蠢的我...没注意到
    猜你喜欢
    • 2014-09-02
    • 1970-01-01
    • 2020-05-29
    • 2010-10-22
    • 2012-02-23
    • 1970-01-01
    • 2021-12-15
    • 2021-09-04
    • 1970-01-01
    相关资源
    最近更新 更多