Vignesh Subramanian
Vignesh Subramanian

Reputation: 7289

adding styles directly to elements in MVC without adding class

I am creating an actionLink in MVC

@Html.ActionLink(item.someId, "SomeDetails", "SomeCase", new { userId = item.userId }, null)

Now i want to add color to it based on a variable i have calculated

for example if i am creating a td i am adding color to it like

<tr style="color:@currentColor">

is there a way like this to add color attribute to the actionLink that i have created? without adding @class="someClassName"

Upvotes: 0

Views: 44

Answers (2)

R P
R P

Reputation: 348

The fourth param you are passing null is going to take a html object. so you can pass the class or style attribute in that param

@Html.ActionLink(item.someId, "SomeDetails", "SomeCase", new { userId = item.userId }, ,  new { @style="color:"+@currentColor })

Upvotes: 2

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

You can do it like this ,

@Html.ActionLink(item.someId, "SomeDetails", "SomeCase", new { userId = item.userId },  new { @style="color:"+currentColor })

Upvotes: 2

Related Questions