如何在C#中的Html.ActionLink上使用CSS [英] How to use CSS on an Html.ActionLink in C#

查看:266
本文介绍了如何在C#中的Html.ActionLink上使用CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了这段代码

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

并链接到css,以便我可以对链接进行样式设置,但是它将链接更改为具有另一个URL,该URL不像没有new { @class = "NavLink" }时那样不属于我的控制器.有什么方法可以让我设置这些链接的样式而又不破坏我的URL,以便使它们转到正确的页面?

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?

谢谢!

推荐答案

确保您使用的是适当的重载:

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

这篇关于如何在C#中的Html.ActionLink上使用CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆