【问题标题】:ASP.NET MVC Razor: how to add a Css style class or ID on the link belowASP.NET MVC Razor:如何在下面的链接中添加 Css 样式类或 ID
【发布时间】:2017-11-23 11:49:48
【问题描述】:

@Html.ActionLink("Some link text", "MyAction", "MyController", protocol: null, hostName: null, fragment: "MyAnchor", routeValues: null, htmlAttributes: null)

电流输出: <a href="/#MyAnchor"> Some Link Text</a>

我希望它是: <a class="smoothScroll" href="/#MyAnchor">Some Link Text</a>

如果他们是在 ASP.NET MVC +4 Razor 中执行此操作的更好方法,请提供帮助。谢谢

【问题讨论】:

标签: asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 razor


【解决方案1】:

将以下内容作为 htmlAttributes 参数传递:

new { @class = "smoothScroll" }

【讨论】:

  • @Html.ActionLink("Some link text", "MyAction", "MyController", protocol: null, hostName: null, fragment: "MyAnchor", routeValues: null, htmlAttributes:new { @ class= "smoothScroll" }) :我在上面试过这段代码
  • 下面那个但是浏览器给了我一个页面不能运行的错误 error new { @class = "smoothScroll" }
  • @Html.ActionLink("Some link text", "MyAction", "MyController", protocol: null, hostName: null, fragment: "MyAnchor", routeValues: null, new { @class = "smoothScroll" })。
  • @PaulT.@TiesonT
猜你喜欢
  • 2011-06-23
  • 2018-01-29
  • 2013-03-08
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
  • 2020-04-12
  • 1970-01-01
相关资源
最近更新 更多