【发布时间】:2018-06-04 06:39:32
【问题描述】:
我想将数据库表中的数据显示到 2x3 网格中。之后将进行分页,因此您可以滑动到所有数据,而不必从上到下列出所有内容。我想知道的是,这是否可以在 cshtml 视图中使用数据表和网格执行?下面是模型。
这是我目前拥有的,现在一切都显示在彼此下方。我想改一下。
查看
@model List<Models.Kolom>
@{
Layout = "";
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Index</h2>
<table class="table">
<thead>
<tr>
<th>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</tbody>
</table>
</body>
</html>
flex-container {
display: flex;
/*Generates a flexbox layout with default flex direction as row */
width: 100%;
/* Not really required */
align-items: center;
/*Aligns contents vertically */
justify-content: center;
/*Aligns contents horizontally */
text-align: center;
/*Aligns further text in the center */
}
.item {
background-color: #1A1919;
height: 500px;
width: 350px;
margin: 5px;
}
<div class="flex-container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="flex-container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="flex-container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
@{ int numberOfRenderedCells = 0; }
@while (numberOfRenderedCells < Model.Count)
{
<div class="flex-container">
@for (var j = 0; j < numberOfCols; j++)
{
if (numberOfRenderedCells < Model.Count)
{
var item = Model.ElementAt(numberOfRenderedCells);
<div class="item">
@Html.DisplayFor(modelItem => item.Naam)
</div>
}
numberOfRenderedCells++;
}
</div>
}
【问题讨论】:
标签: html asp.net-mvc asp.net-mvc-4