我有一个带整数列的表。
根据整数值,我想让单元格中的文本为红色或绿色。
这样的事情就像很多人一样:
List.cshtml:
string style = @DaysLeft <= 30 ? "background-color:Red" : "background-color:Green";
<td style="@style">
...
</td>
如果我将逻辑放在viewmodel中:
public ViewModel()
{
BackgroundColorClass = DaysLeft > 100 ? "Background-color:red" : "Background-color:green";
}
和视图中的类分配:
<td class="CenterOrientedColumns teststateField">
@Html.LabelFor(m => m.DaysLeft, new{ @class = Model.BackgroundColorClass})
</td>
为什么这个逻辑不属于viewmodel?