<div>
<table >
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Type</th>
</tr>
@foreach (var a in Model.Attachments)
{
<tr>
<td>
@a.CId
</td>
<td>
<a href="@Url.Action("ViewAttachment", new { Id = a.CId })">@a.CName</a>
</td>
<td>
@a.CType
</td>
</tr>
}
</table>
@Html.PagedListPager((IPagedList)Model.Attachments, page => Url.Action("Index", new { page }))
</div>
目前我每页显示 25 个项目。如果最后一页没有 25 个项目,我想将行附加到表的末尾,以使页面选择器在页面之间保持同一级别。 这似乎行得通,我只是不知道把它放在哪里:
@for (int i = 25; i > Model.Attachments.Count() % 25; i--)
{
<tr>
<td></td>
</tr>
}
最佳答案
您肯定有一个循环抛出了附件列表。 将此循环放在您编写 TR 的循环之后。
请注意,如果您的数据使您的 TR 更高,这将破坏您的解决方案。您可以尝试的另一件事是在您的虚拟行中添加一个 HTML 空间:
<div>
<table >
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Type</th>
</tr>
@foreach (var a in Model.Attachments)
{
<tr>
<td>
@a.CId
</td>
<td>
<a href="@Url.Action("ViewAttachment", new { Id = a.CId })">@a.CName</a>
</td>
<td>
@a.CType
</td>
</tr>
}
@for (int i = 25; i > Model.Attachments.Count() % 25; i--)
{
<tr>
<td></td>
</tr>
}
</table>
@Html.PagedListPager((IPagedList)Model.Attachments, page => Url.Action("Index", new { page }))
</div>
关于c# - 将行添加到分页列表的最后一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19060955/