如何在 MVC5 中用 Razor 把一行变成红色
How to put a row in red with Razor in MVC5
我有一个 table,我想在实际库存低于最低库存时标记它,因为我将使用 Razor 渲染视图,但我没有得到结果
我附上我的观点,其中包含我们希望干预的 table
<table class="table table-bordered table-hover table-condensed">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().v_Nombre)
</th>
<th>
@Html.DisplayNameFor(model => model.First().StockReal)
</th>
<th>
@Html.DisplayNameFor(model => model.First().StockMinimo)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
var fila = string.Empty;
if(item.StockReal < item.StockMinimo)
{
fila = "danger";
}
<tr class="@fila">
<td>
@Html.DisplayFor(modelItem => item.v_Nombre)
</td>
<td>
@Html.DisplayFor(modelItem => item.StockReal)
</td>
<td>
@Html.DisplayFor(modelItem => item.StockMinimo)
</td>
<td>
<a href="#" class="btn btn-outline-warning" onclick="EditarProducto(@item.Kn_CodigoProducto)">Editar </a>
</td>
</tr>
}
</table>
预期行为:实际库存低于最小库存的行变为红色
实现的行为:我的观点没有改变
我做错了什么?我的 Razor 代码中缺少什么?对我有什么帮助吗?
在 bootstrap 4 中 class
是 table-danger
所以更改您的代码:
if(item.StockReal < item.StockMinimo)
{
fila = "table-danger";
}
我有一个 table,我想在实际库存低于最低库存时标记它,因为我将使用 Razor 渲染视图,但我没有得到结果
我附上我的观点,其中包含我们希望干预的 table
<table class="table table-bordered table-hover table-condensed">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().v_Nombre)
</th>
<th>
@Html.DisplayNameFor(model => model.First().StockReal)
</th>
<th>
@Html.DisplayNameFor(model => model.First().StockMinimo)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
var fila = string.Empty;
if(item.StockReal < item.StockMinimo)
{
fila = "danger";
}
<tr class="@fila">
<td>
@Html.DisplayFor(modelItem => item.v_Nombre)
</td>
<td>
@Html.DisplayFor(modelItem => item.StockReal)
</td>
<td>
@Html.DisplayFor(modelItem => item.StockMinimo)
</td>
<td>
<a href="#" class="btn btn-outline-warning" onclick="EditarProducto(@item.Kn_CodigoProducto)">Editar </a>
</td>
</tr>
}
</table>
预期行为:实际库存低于最小库存的行变为红色
实现的行为:我的观点没有改变
我做错了什么?我的 Razor 代码中缺少什么?对我有什么帮助吗?
在 bootstrap 4 中 class
是 table-danger
所以更改您的代码:
if(item.StockReal < item.StockMinimo)
{
fila = "table-danger";
}