如何在 C# 中的 Html.ActionLink 上使用 CSS

发布于 2024-10-20 11:06:35 字数 286 浏览 7 评论 0原文

我尝试了此代码

<%: Html.ActionLink("Home", "Index", "Home", new { @class = "NavLink" })%>

,它链接到 css这样我就可以设置链接的样式,但它会将链接更改为具有不同的 URL,该 URL 不属于我的控制器,就像没有 new { @class = "NavLink" } 一样。有没有什么方法可以让我设置这些链接的样式而不破坏我的 URL,以便它们转到正确的页面?

谢谢!

I tried this code

<%: Html.ActionLink("Home", "Index", "Home", new { @class = "NavLink" })%>

and it links to the css so that I can style the link, but it changes the link to have a different URL that is not to my controller like it is without the new { @class = "NavLink" }. Is there any way to let me style these links without ruining my URLs so they go to the correct pages?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从来不烧饼 2024-10-27 11:06:35

确保您使用正确的重载

<%: Html.ActionLink("Home", "Index", "Home", null, new { @class = "NavLink" })%>
                                              ^                ^
                                          routeValues    htmlAttributes

Make sure you are using the proper overload:

<%: Html.ActionLink("Home", "Index", "Home", null, new { @class = "NavLink" })%>
                                              ^                ^
                                          routeValues    htmlAttributes
枫林﹌晚霞¤ 2024-10-27 11:06:35

Actionlink 方法有一些重载。

如果你想确定一些 html 属性,你应该使用这样的方法(在你的情况下):

  ActionLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>)
  ActionLink(HtmlHelper, String, String, String, Object, Object)
  ActionLink(HtmlHelper, String, String, String, RouteValueDictionary, IDictionary<String, Object>)

更多关于这里:http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx

Method Actionlink have some overloading.

If you want to determine some html attributes, you should use such methods(in your case):

  ActionLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>)
  ActionLink(HtmlHelper, String, String, String, Object, Object)
  ActionLink(HtmlHelper, String, String, String, RouteValueDictionary, IDictionary<String, Object>)

More about this here: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文