Ejemplo n.º 1
0
        public ActionResult LoadList(int pageSize, int pageIndex)//根据异步分页
        {
            var list = newsInfoBll.GetList(pageSize, pageIndex)
                       .Select(u => new {//避开导航属性
                NewsId     = u.NewsId,
                NewsConent = u.NewsConent,
                RegTime    = u.RegTime,
                TypeConent = u.TypeInfo.TypeConent
            })
                       .ToList();
            int Count     = newsInfoBll.PageCount();                               //获取总条数
            int pageCount = Convert.ToInt32(Math.Ceiling(Count * 1.0 / pageSize)); //获取总页数

            StringBuilder pager = new StringBuilder();

            if (pageIndex == 1)
            {
                pager.Append("首页 上一页");
            }
            else
            {
                pager.Append("<a href='javascript:GoPage(1)'>首页</a>&nbsp;<a href='javascript:GoPage(" + (pageIndex - 1) +
                             ")'>上一页</a>");
            }

            if (pageIndex == pageCount)
            {
                pager.Append("下一页 末页");
            }
            else
            {
                pager.Append("<a href='javascript:GoPage(" + (pageIndex + 1) +
                             ")'>下一页</a>&nbsp;<a href='javascript:GoPage(" + pageCount +
                             ")'>末页</a>");
            }
            var temp = new
            {
                page = pager.ToString(),
                list = list
            };

            return(Json(temp, JsonRequestBehavior.AllowGet));
        }