直接向MVC中的元素添加样式而不添加类

时间:2015-04-01 05:59:17

标签: css asp.net asp.net-mvc

我正在MVC中创建一个actionLink

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

现在我想根据我计算的变量为它添加颜色

例如,如果我正在创建一个td我正在添加颜色,如

<tr style="color:@currentColor">

是否有这样的方法将color属性添加到我创建的actionLink中?没有添加@class="someClassName"

2 个答案:

答案 0 :(得分:2)

你可以这样做,

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

答案 1 :(得分:2)

你传递null的第四个参数将采用一个html对象。所以你可以在那个参数中传递class或style属性

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