MVC异步分页

2020-11-26 13:37

阅读:574

YPE html>

标签:style   blog   class   code   java   ext   

如图:

soscw.com,搜素材

 

1: 控制器代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
        // 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();
 
            //给前台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;
}Index
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)
                {//处理上一页的连接
                    output.AppendFormat("上一页 ", redirectTo, currentPage - 1, pageSize);
                }
                else
                {
                    // output.Append("上一页");
                }

                output.Append(" ");
                int currint = 5;
                for (int i = 0; i = 1 && (currentPage + i - currint) 下一页");
                }
                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异步分页,搜素材,soscw.com

MVC异步分页

标签:style   blog   class   code   java   ext   

原文地址:http://www.cnblogs.com/xiaofengfeng/p/3705632.html


评论


亲,登录后才可以留言!