【问题标题】:adding styles directly to elements in MVC without adding class在 MVC 中直接向元素添加样式而不添加类
【发布时间】:2015-04-01 05:59:16
【问题描述】:

我正在 MVC 中创建一个 actionLink

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

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

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

<tr style="color:@currentColor">

有没有这样的方法可以将颜色属性添加到我创建的 actionLink 中?不加@class="someClassName"

【问题讨论】:

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


    【解决方案1】:

    你可以这样做,

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

    【讨论】:

      【解决方案2】:

      您传递的第四个参数 null 将采用一个 html 对象。因此您可以在该参数中传递类或样式属性

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

      【讨论】:

        猜你喜欢
        • 2012-11-20
        • 2014-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-08
        • 2023-03-15
        • 1970-01-01
        相关资源
        最近更新 更多