6

My code is

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

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

 class="rtsLink" 

Also, can we add multiple css class. 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 am replacing with 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 not working. Thanks

2 Answers 2

13

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 is reserved in C#, so you must prefix it with an @.

Sign up to request clarification or add additional context in comments.

4 Comments

Strange... there's no reason it shouldn't work. What does the rendered html look like?
have you included link to your .css file(on the page you are using this) where these classes are defined ?
It must work. Html.ActionLink usage is true. microtuts.com/…
<li class="rtsLI" id="Summary"><a href="javascript:void(0);" onclick="javascript:rtsMemoTextMenuContainerTabsManager.OnClientTabSelected(this, 0);" class="rtsLink"><span class="rtsTxt">User Security</span></a></li> Above I am replacing with following actionlink:<li class="rtsLI" >@Html.ActionLink("User Security", "Index", new { Area = "Tools", Controller = "UserSecurity" }, new { @class = "rtsLink rtsTxt"})</li> " At first css is working fine. But when using Actionlink, css not working. Thanks
2

Since you have a span inside anchor. You could 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>

1 Comment

Excellent. Thumbs Up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.