c# - 将行添加到分页列表的最后一页

标签 c# html asp.net-mvc

<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/

相关文章:

c# - 如何确定由 Google 翻译翻译的网页的新语言?

c# - 我可以在同一个 Web 应用程序中有 2 个(或更多)不同的 ASP.NET Core 编程模型吗?

html - CSS强制div跟随类

c# - 如何在 Html.DropDownListFor 上选择显示的文本

c# - 在 Blazor View 中调用异步方法

html - <h1> 在 firefox 和 chrome 中小于 <h2>

javascript - 选中复选框时如何激活行的链接

c# - 自定义 DataAnnotationsModelMetadataProvider 不起作用

asp.net-mvc - 如何在 ASP.NET MVC4 Api Controller 中将 View 呈现为字符串

c# - 使用 Entity Framework 4.0 更新分离的实体实例