Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of MVC Asynchronous pagination

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report