1. Pagination Entity class
public class Pagedto {public int PageIndex {get; set;} public int PageSize {get; set;} public int PageCount {get; set;} public int TotalCount {get; set;} }
Back-end Code
Public async task<iactionresult> Index () { var page = httpcontext.request.query["page"]. ToString (); var pageSize = httpcontext.request.query["PageSize"]. ToString (); var searchdto = new Filesearchdto () { PageIndex = string. Isnullorwhitespace (page)? 1:convert.toint32 (page), PageSize = string. Isnullorwhitespace (pageSize)? 5:convert.toint32 (pageSize) }; var results = await _service. Getpagelist (searchdto); var model = new Filelistviewmodel () {Results = Results}; return View (model); }
2. View
@using System.Text; @model baseservice.pagedto@if (Model.totalcount > Model.pagesize) {var controller = Url.actioncon Text. routedata.values["Controller"]; var action = url.actioncontext.routedata.values["Action"]; var url = "/" + controller + "/" + action; var querys = Url.ActionContext.HttpContext.Request.Query; StringBuilder sb = new StringBuilder (); Sb. AppendFormat ("/{0}/{1}?", controller, action); if (Querys! = null && querys. Count > 0) {foreach (var item in Querys) {if (!item. Key.equals ("page")) {sb. AppendFormat ("{0}={1}", item. Key, item. Value); Sb. Append ("&"); }}} sb. Append ("page"); url = sb. ToString (); <div style= "position:fixed;bottom:-15px;text-align:center;width:84%" > <ul class= "Pagination" > 3. Call
@Html. Partial ("~/views/pager/create.cshtml", Model.Results.Page)
. NET MVC Paging