c#中最简单的分页方式

本文关键字:分页 方式 最简单 | 更新日期: 2023-09-27 18:13:54

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

看图片的左下角,看看我所说的分页

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

c#中最简单的分页方式

尝试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 }) )

另外,这个NuGet包也非常有用且易于实现。我强烈建议您使用这个实用程序。

https://github.com/martijnboland/mvcpaging

NuGet [PM> Install-Package MvcPaging]