无为清净楼资源网 Design By www.qnjia.com
如图:
1、控制器代码
// // GET: /AjaxUser/ shopEntities shop = new shopEntities(); public ActionResult Index() { return View(); } public ActionResult loadjson() { int pageSize = Request["pageSize"] == null "pageSize"]); int pageIndex = Request["pageIndex"] == null "pageIndex"]); int totalCount = shop.tbl_admin.Count(); //给前台userinfo所有的数据,并且是json格式 var allorder = shop.tbl_admin.OrderBy(u=>u.id) .Skip(pageSize*(pageIndex-1)) .Take(pageSize) .ToList(); //接受一个对像,内部把此对象使用javaScript序列化类对象志字符串,发送到前台 var data = from u in allorder select new { u.id,u.realname,u.sex}; string strNav = PageNavHelper.ShowPageNavigate(pageIndex,pageSize,totalCount); var result = new {Data=data, NavStr=strNav }; return Json(result, JsonRequestBehavior.AllowGet); }
2、Html代码
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <link href="~/Content/NavPage.css" rel="stylesheet" /> <script src="/UploadFiles/2021-04-02/jquery-1.8.2.min.js">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 <= 0 "<a class='pageLink' href='{0}", redirectTo, pageSize); } if (currentPage > 1) {//处理上一页的连接 output.AppendFormat("<a class='pageLink' href='{0}", redirectTo, currentPage - 1, pageSize); } else { // output.Append("<span class='pageLink'>上一页</span>"); } output.Append(" "); int currint = 5; for (int i = 0; i <= 10; i++) {//一共最多显示10个页码,前面5个,后面5个 if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages) { if (currint == i) {//当前页处理 //output.Append(string.Format("[{0}]", currentPage)); output.AppendFormat("<a class='cpb' href='{0}", redirectTo, currentPage, pageSize, currentPage); } else {//一般页处理 output.AppendFormat("<a class='pageLink' href='{0}", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint); } } output.Append(" "); } if (currentPage < totalPages) {//处理下一页的链接 output.AppendFormat("<a class='pageLink' href='{0}", redirectTo, currentPage + 1, pageSize); } else { //output.Append("<span class='pageLink'>下一页</span>"); } output.Append(" "); if (currentPage != totalPages) { output.AppendFormat("<a class='pageLink' href='{0}", redirectTo, totalPages, pageSize); } output.Append(" "); } output.AppendFormat("第{0}页 / 共{1}页", currentPage, totalPages);//这个统计加不加都行 return output.ToString(); } } }4、分页CSS
body { } .paginator { font: 12px Arial, Helvetica, sans-serif; padding: 10px 20px 10px 0; margin: 0px; } .paginator a { border: solid 1px #ccc; color: #0063dc; cursor: pointer; text-decoration: none; } .paginator a:visited { padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none; } .paginator .cpb { border: 1px solid #F50; font-weight: 700; color: #F50; background-color: #ffeee5; } .paginator a:hover { border: solid 1px #F50; color: #f60; text-decoration: none; } .paginator a, .paginator a:visited, .paginator .cpb, .paginator a:hover { float: left; height: 16px; line-height: 16px; min-width: 10px; _width: 10px; margin-right: 5px; text-align: center; white-space: nowrap; font-size: 12px; font-family: Arial,SimSun; padding: 0 3px; }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
MVC,异步,分页
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月27日
2024年09月27日
- 山风点伙.1997-深藏不露【立得】【WAV+CUE】
- 李幸倪.2018-First.Of.All.Live.Concert.3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】
- 群星《你就在我身边 电影原声专辑》[320K/MP3][26.68MB]
- 群星《你就在我身边 电影原声专辑》[FLAC/分轨][70.27MB]
- 班得瑞原装进口《20周年精选集》1CD[APE/CUE分轨][303MB]
- 群星.2009-NOON.D.广东.2CD【新世纪】【WAV+CUE】
- 洪卓立.2012-GROWN.UP【英皇娱乐】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 金佩姗.1997-喜新恋旧【现代派】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 纯音入心系列纯音乐《云水禅心 - 佛曲古筝礼赞1-2》1CD[MP3][190MB]
- 纯音入心系列纯音乐《精心传神-古筝》1CD[MP3][363.1MB]
- 纯音入心系列纯音乐《琴瑟古风之古筝精选曲》1CD[MP3][354.1MB]