Create a special hash tag anchor tag helper

I am trying to create a special ASP.NET Core tag helper for a tag that supports the asp-hash attribute. This attribute is supposed to simply add the supplied value to the end of the href attribute.

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

will generate:

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

I found the source code for AnchorTagHelper in this section in the asp.net github repo , but I cannot find a way to add content to the end of the generated href .

+5
source share
1 answer

There is no asp-hash attribute, but there is no need to create a special anchor tag helper. You are looking for the asp-fragment attribute:

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

All Articles