asp.net-mvc MVC 5 中的分页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22194716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Paging in MVC 5
提问by Golda
In MVC 5, how to create paging for table? The following is a table structure.
在 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>
回答by Osman M Elsayed
I recommend the PagedList package which is available on nuget
我推荐 nuget 上提供的 PagedList 包
https://www.nuget.org/packages/PagedList
https://www.nuget.org/packages/PagedList
Here is the full documentation
这是完整的文档
回答by BGStack
This tutorial has a good explanation of paging and how to install and use the packages:
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
本教程很好地解释了分页以及如何安装和使用软件包:http:
//www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering -and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
回答by Golda
I have found the solution. Using webgrid, we can achieve the paging
我找到了解决方案。使用webgrid,我们可以实现分页
@model IEnumerable<ItemMaster>
@{
ViewBag.Title = "Item Details";
WebGrid grid = new WebGrid(Model,rowsPerPage:5);
}
<h2>Item Details</h2>
@grid.GetHtml()
回答by Maz H
Grid.MVCis an open source and working Grid with sorting and paging
Grid.MVC是一个开源的工作网格,具有排序和分页功能
(and unlike telerik you do not need to change anything on controller side just add reference in your view and use.)
(与 Telerik 不同,您无需在控制器端更改任何内容,只需在您的视图中添加引用并使用即可。)
To install nugget package (Install)
安装 nugget 包(安装)
PM> Install-Package Grid.Mvc -Version 3.0.0
In your view you can auto-create columns as below (or customize see User Guide)
在您的视图中,您可以自动创建如下列(或自定义,请参阅用户指南)
@using GridMvc.Html
@Html.Grid(Model).AutoGenerateColumns()
See Online Demo
看在线演示

