在MVC 5中进行分页

Gol*_*lda 3 asp.net-mvc pagination html-table razor

在MVC 5中,如何为表创建分页?以下是表结构.

<table class="table">
    <tr>
        <th>
           Item ID
        </th>
        <th>
           Item Name
        </th>
        <th>
           Rate
        </th>
        <th>
          Stock
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ItemID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ItemName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Rate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Stock)
        </td>
    </tr>
}    
</table>
Run Code Online (Sandbox Code Playgroud)

Osm*_*yed 7

我推荐nuget上提供的PagedList包

https://www.nuget.org/packages/PagedList

这是完整的文档

https://github.com/TroyGoode/PagedList