如何在 C# 中的 Html.ActionLink 上使用 CSS
我尝试了此代码
<%: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您使用正确的重载:
Make sure you are using the proper overload:
Actionlink 方法有一些重载。
如果你想确定一些 html 属性,你应该使用这样的方法(在你的情况下):
更多关于这里: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):
More about this here: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx