使用 @Url.Action 在 mvc 中传递部分 ID,以便用户在重定向后滚动到特定部分

passing section id in mvc using @Url.Action so that user will be scrolled to a particular section after redirecting

我是一名网页设计师,但有人告诉我在 mvc 中设计静态页面,而不是使用 href="some url" 我必须使用 href="@Url.Action("Controller" , View)" 现在我想在 url 中传递一个部分 ID,因此当用户重定向时,它将向下滚动到通常在 html 中的特定部分,这是我使用的语法

href="index.html#mysectionid"

在 Html 我有这样的东西

<section id="mysection">

</section>

我想知道我将如何在 mvc 中做这件事。谢谢

您可以在 Razor 中将 C# 代码与正常 html 混合使用:

<a href="@Url.Action("Contact", "Home")#mysection">Test</a>