VSG24 VSG24 - 3 months ago 25
ASP.NET (C#) Question

Creating a custom anchor tag helper with hash string support

I'm trying to create a custom ASP.NET Core tag helper for

a
tag that supports
asp-hash
attribute. What that attribute is supposed to do is just append the provided value to the end of the
href
attribute.

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


would then generate:

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


I found the source code for
AnchorTagHelper
in this section in asp.net github repo but I can't find a way to append stuff to the end of generated
href
.

tmg tmg
Answer

No asp-hash attribute exists, but there is no need to make a custom anchor tag helper. You are looking for asp-fragment attribute:

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