Directly on dry goods
First Nuget package to add a reference: X.PagedList.Mvc.Core
Controller:
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Dw.BLL.Article; using Dw.Models.Article; using Dw.Models.Other; using Microsoft.AspNetCore.Mvc; using X.PagedList; namespace Dw.Histolab.Controllers { public class ArticleController : Controller { private Article_CategoryBLL article_CategoryBLL = new Article_CategoryBLL(); private Article_ContentBLL article_ContentBLL = newArticle_ContentBLL (); #region product list /// <Summary> /// Products /// </ Summary> /// <param name = "the keyValue"> Category primary key </ param> /// <param name = "page"> page several </ param> /// <param name = "the pageSize"> per page recording </ param> /// <Returns> </ Returns> public IActionResult the ProductList ( String the keyValue, int page = 1 ,int pageSize = 12) { var articleCategory = article_CategoryBLL.GetEntity(keyValue); ViewBag.CategoryName = articleCategory.Name; ViewBag.CategoryId = articleCategory.CategoryId; var articleContentList = article_ContentBLL.GetList(keyValue); return View(articleContentList.ToPagedList(page, pageSize)); } #endregion } }
View page
@model X.PagedList.IPagedList<Dw.Models.Article.Article_Content> @using X.PagedList.Mvc.Core; @{ ViewData["Title"] = "产品中心列表"; } <link href="~/css/PagedList.css" rel="stylesheet" /> <div id="contentWrapper"> <div id="contentWrap"> <div id="content"> <div id="prdBrand"> <Category: @ ViewBag.CategoryName>= "bcate"classdiv</div> <div class="item-wrap"> <div class="item-cont"> @foreach (var item in Model) { <dl class="item-list"> <div class="item-icon"> <span class='MK-product-icons'> <img src='~/picture/2903.jpg' class='MK-product-icon-2'> </span> </div> <dt class="thumb"> <a href="shopdetail.html"> <img class="MS_prod_img_m" src="@item.PictureUrl" alt="@item.Title" title="@item.Title"> </a> </dt> <dd> <ul> <li class="prd-name">@item.Title</li> <li class="prd-subname">@item.Summary</Li > </ UL > </ dd > </ DL > } </ div > < div style = "text-align = left: Center" > Per @ Model.PageSize records, records page have @ Model.Count, total @ Model.TotalItemCount records. The first @ (Model.PageCount < Model .PageNumber 0:? Model.PageNumber) Page of @ Model.PageCount page. Html.PagedListPager @ (the Model, Page = > Url.Action ( "the ProductList", new new {Page, the keyValue = ViewBag.CategoryId})) </ div > div> </div> </div> <hr> </div> </div>