开发者

How to use CSS on an Html.ActionLink in C#

开发者 https://www.devze.com 2023-02-15 03:36 出处:网络
I tried this code <%: Html.ActionLink(\"Home\", \"Index\", \"Home\", new { @class = \"NavLink\" })%>

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 link开发者_如何学JAVAs without ruining my URLs so they go to the correct pages?

Thanks!


Make sure you are using the proper overload:

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消