【问题标题】:Why style is not recognized by td element in razor?为什么剃须刀中的 td 元素无法识别样式?
【发布时间】:2019-09-07 06:50:55
【问题描述】:

我在 Razor 代码的 HTML 表中有此列。我想根据状态值改变它的背景。

  <td @(@InspectionReport.Status == 0 ? style = "Background-Color: lightgreen;" : @InspectionReport.Status == 1 ? style = "Background-Color: lightgray;" : @InspectionReport.Status == 2 ? style = "Background-Color: blue;" : @InspectionReport.Status == 3 ? style = "Background-Color: yellow;" : "")>

但它说

样式在当前上下文中不存在

【问题讨论】:

    标签: html asp.net-mvc razor model-view-controller


    【解决方案1】:

    不要直接使用style,而是使用td元素中的某个类

    <td class="@(InspectionReport.Status == 0 ? "lightgreen" : InspectionReport.Status == 1 ? "lightgray" :InspectionReport.Status == 2 ? "blue" : InspectionReport.Status == 3 ? "yellow" : "")"></td>
    

    然后在您的 css 文件中创建类,如下所示:

    td.lightgreen{
        background-color:lightgreen;
    }
    td.lightgray{
        background-color:lightgreen;
    }
    td.blue{
        background-color:blue;
    }
    td.yellow{
        background-color:yellow;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多