Search code examples
asp.net-coreanchorhtml-helper

Add link parameter to asp tag helpers with pound sign (#) anchor url in ASP.NET Core


I have the following url http://localhost:5000/Home/Index/#test and I need to pass the #test to the action. I used asp-route="#test"and asp-route-id="#test" but they does not work.

This is my action:

public ActionResult Index(string id)
{
    return View();
}

Solution

  • Try to use attribute routing

    [Route("Home/Index/{id}")]
    public async Task<IActionResult> Index(string id)
    

    Use tag helpers like

    <a asp-action="Index" asp-controller="Home" asp-route-id="#test">Index</a>