程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

如何在MVC5中用Razor将一行设为红色

发布于2023-12-26 22:15     阅读(340)     评论(0)     点赞(9)     收藏(4)


我有一个表,我想在实际库存低于最低库存时对其进行标记,为此我将使用 Razor 渲染视图,但我没有得到结果

我附上我的视图,其中包含我们希望干预的表

        <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";
}



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.qianduanheidong.com/blog/article/533301/bf3523ceb0e2e032b08b/

来源:前端黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

9 0
收藏该文
已收藏

评论内容:(最多支持255个字符)