• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

MVC异步分页代码分享

asp 搞代码 4年前 (2022-01-03) 18次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了MVC异步分页代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

如图:

 

1、控制器代码 

 // // GET: /AjaxUser/ shopEntities shop <strong style="color:transparent">来源gaodai#ma#com搞@@代~&码网</strong>= 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(); //给前台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; }   <title>Index</title> <div> <table id="tbList"> <tr> <td>id</td><td>姓名</td><td>性别</td><td>操作</td></tr></table><div id="Nav" class="paginator"> </div></div>

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) {//处理上一页的连接 output.AppendFormat("上一页 ", redirectTo, currentPage - 1, pageSize); } else { // output.Append("<span class='pageLink'>上一页</span>"); } output.Append(" "); int currint = 5; for (int i = 0; i = 1 && (currentPage + i - currint) <= totalPages) { if (currint == i) {//当前页处理 //output.Append(string.Format("[{0}]", currentPage)); output.AppendFormat("{3} ", redirectTo, currentPage, pageSize, currentPage); } else {//一般页处理 output.AppendFormat("{3} ", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint); } } output.Append(" "); } if (currentPage <totalPages) {//处理下一页的链接 output.AppendFormat("下一页 ", redirectTo, currentPage + 1, pageSize); } else { //output.Append("<span class='pageLink'>下一页</span>"); } output.Append(" "); if (currentPage != totalPages) { output.AppendFormat("末页 ", 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异步分页代码分享的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:MVC异步分页代码分享
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址