我有以下网址http://localhost:5000/Home/Index/#test
,我需要将#test
传递给行动。我使用asp-route="#test"
and asp-route-id="#test"
但它们不起作用。
这是我的行动:
public ActionResult Index(string id)
{
return View();
}
[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>
URL的哈希或片段部分不是路由的一部分。它只对客户端有意义。我认为没有办法通过标签助手添加它。相反,你需要使用像Url.Action
这样的东西:
<a href="@Url.Action("Index", "Home")#test">My Link</a>