【问题标题】:Adding rows to the final page of a pagedlist将行添加到分页列表的最后一页
【发布时间】:2013-09-27 22:17:39
【问题描述】:
<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>
}

【问题讨论】:

    标签: c# html asp.net-mvc


    【解决方案1】:

    您肯定有一个循环抛出了附件列表。 将此循环放在您编写 TR 的循环之后。

    请注意,如果您的数据使您的 TR 更高,这将破坏您的解决方案。您可以尝试的其他方法是在虚拟行中添加 HTML 空间:&amp;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>
    

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 2020-07-10
      • 1970-01-01
      • 2021-06-06
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多