asp.net - PartialView 中的水平表格 HTML
问题描述
我正在使用 Asp.Net Core MVC 开发 Web 应用程序项目,其中我有一个显示水平表的视图。我正在使用部分视图来实现这一点,但我一直坚持如何表示固定的五行,如下所示:
- 天
- 日期
- 合适的
- 不当
- 无交互
每行将动态打印值。
这是我的视图,它按预期通过了所有内容。
<form method="get" asp-action="details">
<table class="table order-list">
<thead>
@for (int i = 0; i < Model.SessionList.Count; i++)
{
<partial name="_ChartDetailsPartial" for="@Model.SessionList[i]"
/>}
</thead>
</table>
</form>
这是我的部分视图,我想在那里显示和安排所有内容。
@model TestApplication.Models.ViewModels.SessionViewModel
@{
ViewData["Title"] = "_ChartDetailsPartial";
}
<input type="hidden" asp-for="Id" />
<tr>
<th>Day</th>
@for (int i = 0; i < 16; i++)
{
<td>@Html.DisplayFor(m => m.Day)</td>
}
</tr>
<tr>
<th width="200">Date</th>
@for (int i = 0; i < 16; i++)
{
<td>@Html.DisplayFor(m => m.Date)</td>
}
</tr>
<tr>
<th style="text-decoration: underline limegreen">Appropriate Data</th>
@for (int i = 0; i < 16; i++)
{
<td>@Html.DisplayFor(m => m.Appropriate)</td>
}
</tr>
<tr>
<th style="text-decoration: underline red">InAppropriate Data</th>
@for (int i = 0; i < 16; i++)
{
<td>@Html.DisplayFor(m => m.NotAppropriate)</td>
}
</tr>
<tr>
<th style="text-decoration: underline darkgray">No Interaction Data</th>
@for (int i = 0; i < 16; i++)
{
<td>@Html.DisplayFor(m => m.NoInteraction)</td>
}
</tr>
我想要实现的类似于下图:
解决方案
这是一个工作演示,如下所示:
模型:
public class TestViewModel
{
public List<SessionViewModel> SessionList { get; set; }
}
public class SessionViewModel
{
public int Id { get; set; }
public int Day { get; set; }
public int Date { get; set; }
public int Appropriate { get; set; }
public int NotAppropriate { get; set; }
public int NoInteraction { get; set; }
}
看法:
@model TestViewModel
<form method="get" asp-action="details">
<table class="table order-list">
<thead>
<tr>
<th> </th>
@for (int i = 1; i <= Model.SessionList.Count(); i++)
{
<th>@i</th>
}
</tr>
</thead>
<tbody>
<partial name="_ChartDetailsPartial" for="@Model.SessionList" />
</tbody>
</table>
</form>
部分视图:
@model List<SessionViewModel>
<tr>
<th>Day</th>
@for (int i = 0; i < Model.Count(); i++)
{
<input type="hidden" asp-for="@Model[i].Id" />
<td>@Html.DisplayFor(m => m[i].Day)</td>
}
</tr>
<tr>
<th width="200">Date</th>
@for (int i = 0; i < Model.Count(); i++)
{
<td>@Html.DisplayFor(m => m[i].Date)</td>
}
</tr>
<tr>
<th style="text-decoration: underline limegreen">Appropriate Data</th>
@for (int i = 0; i < Model.Count(); i++)
{
<td>@Html.DisplayFor(m => m[i].Appropriate)</td>
}
</tr>
<tr>
<th style="text-decoration: underline red">InAppropriate Data</th>
@for (int i = 0; i < Model.Count(); i++)
{
<td>@Html.DisplayFor(m => m[i].NotAppropriate)</td>
}
</tr>
<tr>
<th style="text-decoration: underline darkgray">No Interaction Data</th>
@for (int i = 0; i < Model.Count(); i++)
{
<td>@Html.DisplayFor(m => m[i].NoInteraction)</td>
}
</tr>
推荐阅读
- cassandra - Apache Cassandra 3.11.6:集群键错误,cass-stress 写入后表中未定义的列名
- android - Android:更正 Nexus 5 和 Pixel 3a 的尺寸值
- python - 来自 statsmodels 的自定义估计器 WLS 的 sklearn check_estimator 错误
- sentry - 哨兵在 react-native 中没有捕捉到本地粉碎
- ruby-on-rails - 缓存的 Ruby Haml 块返回空
- css - 响应式 css 网格 - 如何使第一项 2 x 宽度和响应式
- javascript - 为什么在附加到文档时会忽略某些 keydown 事件?
- elasticsearch - 在 Windows 10 中哪里可以找到 Kibana 系统日志文件
- r - 如何创建标识行值更改的另一列的列?
- c++ - 如何在正在运行的代码中的任何地方暂停和恢复(使用用户输入)?