创建具有哈希字符串支持的自定义锚标记助手
Creating a custom anchor tag helper with hash string support
我正在尝试为支持 asp-hash
属性的 a
标签创建自定义 ASP.NET 核心标签助手。该属性应该做的只是将提供的值附加到 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
.
不存在 asp-hash
属性,但无需制作自定义锚标记助手。您正在寻找 asp-fragment
属性:
<a asp-controller="Home" asp-action="Index" asp-fragment="mainDiv">some link</a>
我正在尝试为支持 asp-hash
属性的 a
标签创建自定义 ASP.NET 核心标签助手。该属性应该做的只是将提供的值附加到 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
.
不存在 asp-hash
属性,但无需制作自定义锚标记助手。您正在寻找 asp-fragment
属性:
<a asp-controller="Home" asp-action="Index" asp-fragment="mainDiv">some link</a>