c# - 使用 MVC3 C# 进行分页的最简单方法?

标签 c# asp.net-mvc-3 paging

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

看图的左下角就明白我说的分页是什么意思了

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

最佳答案

尝试 PagedList .有一个 NuGet package用于 MVC。

@{
    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 }) )

关于c# - 使用 MVC3 C# 进行分页的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8070030/

相关文章:

ajax - 除非显示/隐藏过滤器以重新调整视口(viewport)大小,否则 SlickGrid 垂直滚动条无法正确显示

.net - 分页选择,在数据库上或在 web 应用程序中

linux - 多级页表概念

asp.net-mvc-3 - 如何让 User.Identity 在 Controller 外工作

c# - MVC 3 注册确认邮件

c# - 带有重音符号的 MailMessage 附件文件名

c# - 如何对学生列表进行排序?

c# - 让 AppSettingsReader 询问值的类型并返回一个非特定类型的对象有什么意义?

c# - Select2 With Ajax Asp.net 4.0 webmethod 请求

asp.net-mvc - 如何在每个页面的第一次点击中提高 ASP.Net MVC3 性能?