How to create multiple tables from one module in MVC view?

拟墨画扇 提交于 2020-06-01 05:08:35

问题


I need to create multiple tables from one module in mvc view , I created 2 header and 2 foreach but when i run the view its not seperated and second set of columns header not appeared only one set of header columns at the beginning of view , How to seperate the view and show multiple tables include header and columns ?

This is my View code :

@model IEnumerable<AljawdahNewSite.Models.Orders_Tables>
@{
    ViewBag.Title = "Details1";
    Layout = "~/Views/Shared/_LayoutPatients.cshtml";
    var ids = new List<int>() { 1, 2, 3, 4 };
}

Then this is first table :

@if (ids.Contains(Model.First().labCashView.DEPTID.GetValueOrDefault()))
{
 <div class="tab-content">
     <div class="tab-pane container active p-0" style="margin-left:15px">
         <hr />
         <dl class="horizontal" style="border:solid">
             <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Patient_Name)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Patient_Name)</dd>
             <dt style="width: 22%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Customer_Name)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Customer_Name)</dd>
             <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Patient_No)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Patient_No)</dd>
             <dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Collection_Date)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Collection_Date)</dd>
             <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.SEX)</dt>
             <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.SEX)</dd>
             <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Receiving_Date)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Receiving_Date)</dd>
             <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.AGE)</dt>
             <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.AGE)</dd>
             <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Report_Date)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Report_Date)</dd>
             <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.order_number)</dt>
             <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.order_number)</dd>
         </dl>


         <table id="menu" class="table table-bordered table-striped">
             <tr>

                 <td> test name    </td>
                 <td> result  </td>
                 <td> From Range   </td>
                 <td> To Range </td>
                 <td> Other Range    </td>
                 <td> Report Date  </td>


             </tr>
             <tbody>
             @foreach (var item in Model.Where(x => ids.Contains(x.labCashView.DEPTID.GetValueOrDefault())))
             {
                     <tr>

                         <td>@item.labCashView.Test_Name</td>
                         <td>@item.labCashView.Result</td>
                         <td>@item.labCashView.Low_Range</td>
                         <td>@item.labCashView.High_Range</td>
                         <td style="width:20%">@item.labCashView.Text_Range</td>
                         <td>@item.labCashView.Report_Date.Value.ToShortDateString()</td>


                     </tr>

             }
                 </tbody>


         </table>
         <hr />


     </div>
 </div>

}

And second table :

     @if (Model.First().labCashView.DEPTID == 6)
 {   <div class="tab-content">
         <div class="tab-pane container fade p-0" style="margin-left:15px">
             <hr />

                 <dl class="horizontal" style="border:solid">
                     <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Patient_Name)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Patient_Name)</dd>
                     <dt style="width: 22%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Customer_Name)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Customer_Name)</dd>
                     <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Patient_No)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Patient_No)</dd>
                     <dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Collection_Date)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Collection_Date)</dd>
                     <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.SEX)</dt>
                     <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.SEX)</dd>
                     <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Receiving_Date)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Receiving_Date)</dd>
                     <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.AGE)</dt>
                     <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.AGE)</dd>
                     <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Report_Date)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Report_Date)</dd>
                     <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.order_number)</dt>
                     <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.order_number)</dd>
                 </dl>




             <table id="menu1" class="table table-bordered table-striped">
                 <tr>

                     <td> test name    </td>
                     <td> result  </td>
                     <td> From Range   </td>
                     <td> To Range </td>
                     <td> Other Range    </td>
                     <td> Report Date  </td>


                 </tr>
                 <tbody>
                     @foreach (var item in Model.Where(x => x.labCashView.DEPTID == 6))
                     {
                         <tr>

                             <td>@item.labCashView.TEXT</td>
                             <td>@item.labCashView.TEST_RESULT</td>
                             <td>@item.labCashView.UNIT</td>
                             <td>@item.labCashView.Text_Range</td>
                             <td>@item.labCashView.Report_Date.Value.ToShortDateString()</td>


                         </tr>
                     }
                 </tbody>

             </table>
             <hr />



         </div>
    </div>

 }

when run the view in browser its appear one header and one table second header and second foreach not appeared :

First table appeared correct like the image :

How to separate 2 tables and show each header and data in view each in one page ?

来源:https://stackoverflow.com/questions/62086222/how-to-create-multiple-tables-from-one-module-in-mvc-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!