【问题标题】:The easiest way for paging with MVC3 C#?使用 MVC3 C# 进行分页的最简单方法?
【发布时间】:2011-11-09 18:53:48
【问题描述】:

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

看图左下角,看看我说的分页是什么意思

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

【问题讨论】:

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


    【解决方案1】:

    试试PagedList。 MVC 有一个 NuGet package

    @{
        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 包:install-package PagedList ...非常简单:)
    【解决方案2】:

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

    https://github.com/martijnboland/mvcpaging

    NuGet [PM> 安装包 MvcPaging ]

    【讨论】:

      猜你喜欢
      • 2013-03-06
      • 2013-07-17
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      相关资源
      最近更新 更多