Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of MVC Asynchronous pagination

Shulou Source: shulou.com Published: 2022-06-03 13:00:25 11月14日 Update

This article will explain in detail the example analysis of MVC asynchronous paging. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

As shown in the figure:

1. Controller code

/ GET: / AjaxUser/ shopEntities shop = new shopEntities (); public ActionResult Index () {return View ();} public ActionResult loadjson () {int pageSize = Request ["pageSize"] = = null? 10: int.Parse (Request ["pageSize"]); int pageIndex = Request ["pageIndex"] = = null? 1: int.Parse (Request ["pageIndex"]); int totalCount = shop.tbl_admin.Count () / / give all the data to the front desk userinfo, and the format is json var allorder = shop.tbl_admin.OrderBy (u = > u.id) .Skip (pageSize* (pageIndex-1)) .take (pageSize) .ToList () / / accept an object, internally use javaScript to serialize the object log string, send it to the foreground var data = from u in allorder select new {u.idreu.realnameplayu.sex}; string strNav = PageNavHelper.ShowPageNavigate (pageIndex,pageSize,totalCount); var result = new {Data=data, NavStr=strNav}; return Json (result, JsonRequestBehavior.AllowGet);}

2. Html code

@ {Layout = null;} Index $(function () {/ / after loading the current page data such as initTable ();}); / / initialize the tabular data function initTable (queryData) {$.getJSON ("/ AjaxUser/loadjson", queryData, function (data) {var tb = $("# tbList") / / remove the old one first and add a new $("# tbList tr [type=data]") .remove (); for (var I = 0; I)

< data.Data.length; i++) { var strTr = ""; strTr += "" + data.Data[i].id + ""; strTr += "" + data.Data[i].realname + ""; strTr += "" + data.Data[i].sex + ""; strTr += "修改" + "删除"; strTr += ""; tb.append(strTr); } $("#Nav").html(data.NavStr); //绑定分页标签的点击事件 $(".pageLink").click(function () { //把页码弹出来 var strHref = $(this).attr("href"); var queryStr = strHref.substr(strHref.indexOf('?') + 1); //alert(queryStr); initTable(queryStr); return false; }); }); } id 姓名 性别 操作 3、分页类 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web;namespace MvcTest4.Models{ public class PageNavHelper { //主要就是输出分页的超级链接的标签 //自定义分页Helper扩展 public static string ShowPageNavigate(int currentPage, int pageSize, int totalCount) { var redirectTo = HttpContext.Current.Request.Url.AbsolutePath; pageSize = pageSize 1) { //if (currentPage != 1) {//处理首页连接 output.AppendFormat("首页 ", redirectTo, pageSize); } if (currentPage >

1) {/ / handle the previous page's connection output.AppendFormat ("previous page", redirectTo, currentPage-1, pageSize);} else {/ / output.Append ("previous page");} output.Append (""); int currint = 5; for (int I = 0; I = 1 & (currentPage + I-currint)

Tags: Processing data article previous example analysis code foreground object more tag link home page good practical event content name character string Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Microsoft NVidia OPPO Reno