c# - 创建具有哈希字符串支持的自定义 anchor 标记助手

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

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

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

然后会生成:

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

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

最佳答案

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

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

关于c# - 创建具有哈希字符串支持的自定义 anchor 标记助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38620252/

相关文章:

c# - ASP.NET Core Identity 2.0 - 将 401 状态代码返回到 ajax 函数

asp.net-mvc - 新的 ASP.NET MVC 6 标识中的 AspNetUsers 表中的 ConcurrencyStamp 列的用途是什么?

c# - 如何对锁定语句进行单元测试?

c# - 手动触发按钮(或任何控件)单击事件。 C#

c# - Blazor 错误 400,ReasonPhrase 错误请求版本 : 1. 1 System.Net.Http.BrowserHttpHandler

linux - 使用 .Net Core Web API 在 linux VM 上安装 SSL 证书

c# - 身份不工作,无法访问身份数据

asp.net-mvc - 针对同一元素的多个标签助手

c# - 告诉 Swashbuckle 只查找具有 ApiControllerAttribute 的 Controller

c# - 清除页面在 WP8 中使用的内存