How to enable CSS class in ActionLink in MVC4

My code

@Html.ActionLink("test1", "Index", new { Area = "area1", Controller = "controller1" }) 

I want to include the following css class in the action link.

  class="rtsLink" 

You can also add several css classes. If so, I need to add another css class.

 class="rtsTxt" 

Update:

 <li class="rtsLI" id="Summary"><a href="javascript:void(0);" onclick="javascript:rtsXXX.OnClientTabSelected(thisβ€Œβ€‹, 0);" class="rtsLink"><span class="rtsTxt">Test</span></a></li> 

Above, I replace the following actionlink:

 <li class="rtsLI" >@Html.ActionLink("test1", "Index", new { Area = "Tools", Controller = "controller1" }, new { @class = "rtsLink rtsTxt"})</li> " 

At first css is working fine. But when using Actionlink css does not work. thanks

+6
source share
2 answers

You can simply add a new anonymous object as the fourth parameter

 @Html.ActionLink("User Security", "Index", new { Area = "Tools", Controller = "UserSecurity" }, new { @class = "rtsLink rtsTxt" }) 

Note that the word class reserved in C #, so you must prefix it with @ .

+13
source

Since you have a span inside the anchor . You can try this.

 <li class="rtsLI" id="Summary"> <a href="@Url.Action("Index", new { Area = "Tools", Controller = "UserSecurity" })" class="rtsLink"> <span class="rtsTxt">User Security</span> </a> </li> 
+2
source

Source: https://habr.com/ru/post/924241/


All Articles