使用ASP.NET Core中的井号(#)锚点URL将链接参数添加到asp标记助手

问题描述 投票:-1回答:2

我有以下网址http://localhost:5000/Home/Index/#test,我需要将#test传递给行动。我使用asp-route="#test"and asp-route-id="#test"但它们不起作用。

这是我的行动:

public ActionResult Index(string id)
{
    return View();
}
asp.net-core anchor html-helper
2个回答
1
投票

尝试使用attribute routing

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

使用Tage helpers之类的

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

0
投票

URL的哈希或片段部分不是路由的一部分。它只对客户端有意义。我认为没有办法通过标签助手添加它。相反,你需要使用像Url.Action这样的东西:

<a href="@Url.Action("Index", "Home")#test">My Link</a>
© www.soinside.com 2019 - 2024. All rights reserved.