【问题标题】:How to incorporate href to section with Html.ActionLink in MVC?如何在 MVC 中将 href 与 Html.ActionLink 部分合并?
【发布时间】:2015-06-16 02:07:54
【问题描述】:

我是 MVC 新手,遇到了问题。我有一个 HTML 页面,当从导航栏中单击该部分的名称时,该页面会向下滚动到该部分,但现在我必须将此 HTML 代码行更改为 MVC:

<li><a class="page-scroll" href="#services">Services</a></li>

我尝试过使用 Html.ActionLink 但还没有成功!

到目前为止我所拥有的:

@Html.ActionLink("Services", "Index", "Home", new { area = "#services" }, new { @class = "page-scroll" })

【问题讨论】:

标签: html asp.net-mvc


【解决方案1】:

创建您自己的助手或使用原始 html

&lt;li&gt;&lt;a href="@Url.Action("Action", "Controller")#services"&gt;Link Text&lt;/a&gt;&lt;/li&gt;

&lt;%= Html.ActionLink("Link Text", "Action", "Controller", null, null, "services", new { parameter = "example"}, null) %&gt;

在您的索引页面上:

<div id="services"> <p>Here is the content you want to make show when you click the link</p> </div>

当您单击“链接文本”时,它会将您定向到索引页面的服务部分。

【讨论】:

  • 谢谢!
【解决方案2】:

试试

@Html.ActionLink("Services", "Index", "Home#services", new { @class = "page-scroll" })

【讨论】:

    猜你喜欢
    • 2012-09-23
    • 2015-01-27
    • 1970-01-01
    • 2021-05-25
    • 2010-11-29
    • 2013-07-27
    • 2018-01-20
    • 2017-06-09
    • 1970-01-01
    相关资源
    最近更新 更多