使用MVC3 C#进行分页的最简单方法是什么?

Xtr*_*eme 4 c# paging asp.net-mvc-3

在MVC3 C#中有一个网站项目,我从数据库中检索信息并在我的视图中的表格中显示.我想使用分页每页最多显示五行.一直在寻找互联网上的教程,但他们似乎都很先进,以实现它.使用MVC3进行分页的最简单方法是什么?

查看图片的左下角,看看我的意思是分页

分页http://www.syncfusion.com/content/en-US/products/feature/user-interface-edition/aspnet-mvc/grid/img/Paging_Larger.jpg

jru*_*ell 8

尝试PagedList.MVC 有一个NuGet包.

@{
    ViewBag.Title = "Product Listing"
}
@using PagedList.Mvc; //import this so we get our HTML Helper
@using PagedList; //import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)

<!-- import the included stylesheet for some (very basic) default styling -->
<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />

<!-- loop through each of your products and display it however you want. we're just printing the name here -->
<h2>List of Products</h2>
<ul>
    @foreach(var product in ViewBag.OnePageOfProducts){
        <li>@product.Name</li>
    }
</ul>

<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
@Html.PagedListPager( (IPagedList)ViewBag.OnePageOfProducts, page => Url.Action("Index", new { page }) )
Run Code Online (Sandbox Code Playgroud)