在MVC3 C#中有一個網站項目,我從數據庫中檢索信息並在我的視圖中顯示在表格中。我想使用分頁來顯示每頁最多五行。一直在互聯網上尋找教程,但他們似乎都非常先進,以實現它。使用MVC3進行分頁的最簡單方法是什麼?用MVC3 C#分頁最簡單的方法?
看在圖片的左下角,看看我的意思是尋呼
在MVC3 C#中有一個網站項目,我從數據庫中檢索信息並在我的視圖中顯示在表格中。我想使用分頁來顯示每頁最多五行。一直在互聯網上尋找教程,但他們似乎都非常先進,以實現它。使用MVC3進行分頁的最簡單方法是什麼?用MVC3 C#分頁最簡單的方法?
看在圖片的左下角,看看我的意思是尋呼
嘗試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包也非常有用,易於實現。我強烈建議通過這個實用程序。
https://github.com/martijnboland/mvcpaging
的NuGet [PM>安裝,包裝MvcPaging]
感謝提NuGet包:安裝包PagedList ...很容易:) – SwissCoder