我想用红色和绿色显示<td>值。如果“检测到”红色和“没有检测”绿色字体应该来。@model.status应该动态改变字体的颜色
视图
<tbody>
<tr>
<td>@Model.UpdatedTime</td>
<td>@Model.status</td>
</tr>
</tbody>控制器
if (status == "UP") {
ViewBag.data = "OPEN";
ViewBag.StatusImg = "/images/intrusion.jpg";
model.status = "DETECTED";
model.ImageUrl = "/images/normal.jpg";
}发布于 2017-10-05 10:30:57
您可以在Razor中使用if-else阻止内部视图。
<tbody>
<tr>
<td>@Model.UpdatedTime</td>
@if(Model.status == "DETECTED"){
<td style="background-color:red">Model.status</td>
} else{
<td style="background-color:green">Model.status</td>
}
</tr>
</tbody>https://stackoverflow.com/questions/46583250
复制相似问题