将行添加到页面列表的最后一页

时间:2013-09-27 22:17:40

标签: 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>
}

1 个答案:

答案 0 :(得分:0)

您肯定会抛出一个循环抛出附件列表。 将这个循环放在你编写TR的循环之后。

考虑到如果您的数据使您的TR更高,这将破坏您的解决方案。您可以尝试的另一件事是在虚拟行中添加HTML空间:&nbsp;

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