發(fā)表日期:2017-08-08 文章編輯:南昌開優(yōu)網(wǎng)絡(luò) 瀏覽次數(shù):5644 標(biāo)簽:ASP.NET應(yīng)用
public ActionResult Index(int pageIndex = 1) { if (pageIndex < 1) { pageIndex = 1; //最少為第一頁 } int pageSize = 10; //每頁顯示數(shù) string cond = ""; //條件 int total = new DAL.ArticleDAL().CalcCount(cond); //總記錄 List<Model.Article> list = new DAL.ArticleDAL().GetListArray("*", "sort_id asc,createdate desc,id desc", pageSize, pageIndex, cond); //獲取數(shù)據(jù)列表,即分頁函數(shù) PagedList<Model.Article> mlist = new PagedList<Model.Article>(list, pageIndex, pageSize, total); //分頁 return View(mlist); //返回列表 }
@using Webdiyer.WebControls.Mvc; @model PagedList<XiaobinManage.Model.Article> @{ //ViewBag.title = "新聞列表"; Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>@ViewBag.title</title> <link href="/css/page.css" rel="stylesheet" /> </head> <body> @foreach (var item in Model) { <div> @item.title - @item.createdate.ToString("yyy-MM-dd") </div> } <div class="pagesDiv"> @*@Model.TotalItemCount 總記錄數(shù), @Model.CurrentPageIndex 當(dāng)前頁, @Model.TotalPageCount 總頁數(shù), PageIndexParameterName = "pageIndex" 頁索引參數(shù)名稱, NumericPagerItemCount = 5 顯示數(shù)字按鈕個數(shù), ShowMorePagerItems = false 是否顯示更多, CurrentPagerItemTemplate = "<span class=\"cpb\">{0}</span>" 當(dāng)前頁的樣式, DisabledPagerItemTemplate = "<a disabled=\"disabled\">{0}</a>" 禁用頁索引的樣式 *@ <span style="float: left;">共 @Model.TotalItemCount 條記錄,第 @Model.CurrentPageIndex 頁/共 @Model.TotalPageCount 頁</span> @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", CssClass = "pages", NumericPagerItemCount = 5, ShowMorePagerItems = false, CurrentPagerItemTemplate = "<span class=\"cpb\">{0}</span>", DisabledPagerItemTemplate = "<a disabled=\"disabled\">{0}</a>" }) </div> </body> </html>