• 1000 начало представления, Как разделить представление и показать несколько таблиц, включая заголовок и столбцы?
Это мой код представления:
@model IEnumerable<AljawdahNewSite.Models.Orders_Tables>
@{
ViewBag.Title = "Details1";
Layout = "~/Views/Shared/_LayoutPatients.cshtml";
var ids = new List<int>() { 1, 2, 3, 4 };
}
Тогда это первая таблица:
@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>
}
И вторая таблица:
@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>
}
при запуске представления в браузере появляется один заголовок и второй заголовок таблицы, а второй foreach не отображается:
Первая таблица выглядит правильно, как и изображение:
введите описание изображения здесь
Как разделить 2 таблицы и отобразить каждый заголовок и данные в представлении на одной странице?