【MVC】List类型model界面显示问题

最近需要做一个页面,类似于excle表,上面部分是表格基础信息,下面部分是一个List信息包含每一行的信息,在MVC中建立一个大model包含小model List的方式。

    public class BaseTableModel : BaseModel
    {
        public BaseTableListModel()
        {
            this.DetailList1 = new List<DetailModel>();
            this.DetailList2 = new List<DetailModel>();
        }

        [ColumnName("ID")]
        public int ID { get; set; }
        
        [ColumnName("NAME")]
        public string NAME { get; set; }
        
        [ColumnName("REV")]
        public string REV { get; set; }

        [ColumnName("COMMENTS")]
        public string COMMENTS { get; set; }

        [ColumnName("USER_ID")]
        public string USER_ID { get; set; }

        [ColumnName("UP_TIME")]
        public string UP_TIME { get; set; }

        [ColumnName("STATUS")]
        public string STATUS { get; set; }

        public List<DetailModel> DetailList1 { get; set; }
        public List<DetailModel> DetailList2 { get; set; }
    }

    public class DetailTableModel : BaseModel
    {
        [ColumnName("ID")]
        public int? ID { get; set; }

        [ColumnName("STAGE")]
        public string STAGE { get; set; }

        [ColumnName("PARAMETER")]
        public string ATE_TEST_PARAMETER { get; set; }
 
    }

在视图中,充分利用分部视图,显示Detail1和Detail2的信息。
主视图中

<div class="container-fliud">
    <table class="formtable">
        <tr>
            <td style="width: 125px; font-weight: bold;">
                <req>*</req>
                Name
            </td>
            <td>
                @Html.HiddenFor(m => m.ID)
                @Html.TextBoxFor(m => m.NAME, new { @class = "form-control", @readonly = "readonly" })
                @Html.ValidationMessageFor(m => m.NAME)
            </td>
            <td style="width: 110px; font-weight: bold;">
                <req>*</req>
                REV
            </td>
            <td>
                @Html.TextBoxFor(m => m.REV, new { @class = "form-control", @readonly = "readonly" })
                @Html.ValidationMessageFor(m => m.REV)
            </td>

            <td colspan="10" style="text-align: left; font-weight: bold">
                <req>*</req>
                Comments
            </td>
        </tr>
        <tr>
            <td colspan="10" style="text-align:left;">
                @Html.TextAreaFor(m => m.COMMENTS, new { @class = "form-control", @style = "height:50px; resize:vertical" })
                @Html.ValidationMessageFor(m => m.COMMENTS)
            </td>
        </tr>
    </table>
</div>

<div class="row" style="color:mediumaquamarine">
    <div class="col-md-12">
        <h4>Table Detail</h4>
    </div>
</div>

<ul class="nav nav-tabs">
    <li class="active"><a href="#DetailTab1" role="tab" data-toggle="tab">Detail1</a></li>
    <li><a href="#DetailTab2" role="tab" data-toggle="tab">Detai2</a></li>
</ul>

<div class="tab-content" style="padding:10px">

    <div class="tab-pane active" id="RoomTab">
        <div class="container-fliud">
            <div class="panel-heading" style="padding:5px 0px;">
            Detail1
            </div>
            @Html.Partial("_DetailListPartial", Model.DetailList1, new ViewDataDictionary(ViewData) { { "name", "DetailList1" } })
        </div>
    </div>

    <div class="tab-pane" id="HotTab">
        <div class="container-fliud">
            <div class="panel-heading" style="padding:5px 0px;">
            Detail2
            </div>
            @Html.Partial("_DetailListPartial", Model.DetailList2, new ViewDataDictionary(ViewData) { { "name", "DetailList2" } })
        </div>
    </div>

在分部视图中,传入一个ViewDataDictionary,包含需要在分部视图中做出区别的数据,比如在本页面中,需要修改分布视图中Detail的ID和name,便于直接传输到后台

@model List<Models.xxx.BaseTable.DetailTableModel>
@{
    string stage = ViewData["name"].ToString();
}

@*<div style="max-height: 480px; overflow: auto">*@
<table class="table table-hover table-bordered table-condensed" id=@stage>
    <thead>
        <tr class="active">
            <th>ID</th>
            <th>Stage</th>
            <th>Prameter</th>
        </tr>
    </thead>
    @{
        <tbody>
            @if (Model != null && Model.Count != 0)
            {
                for (int i = 0; i < Model.Count; i++)
                {
                    <tr>
                        <td>
                            @Html.TextBox(stage + "[" + i + "].ID", Model[i].ID, new { @class = "form-control" })
                        </td>
                        <td>
                            @Html.TextBox(stage + "[" + i + "].STAGE", Model[i].STAGE, new { @class = "form-control" })
                        </td>
                        <td style="width:20%">
                            @Html.TextBox(stage + "[" + i + "].PARAMETER", Model[i].PARAMETER, new { @class = "form-control" })
                        </td>
                    </tr>
                }
            }
</table>
@*</div>*@
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值