其他分享
首页 > 其他分享> > mvc.net分页查询案例——PagedList

mvc.net分页查询案例——PagedList

作者:互联网

在.net中,除了人手动写分页类之外,微软还提供了官方的分页,分页工具类包括PagedList和PagerExtension,先来看看PagedList类里面是怎么写的:

PagedList

using System;
using System.Collections.Generic;
using System.Linq;

namespace System.Web.Mvc
{
    public class PagedList<T> : List<T>
    {

        /// <summary>
        /// 页索引
        /// </summary>
        public int PageIndex { get; private set; }

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; private set; }

        /// <summary>
        /// 总数据条数
        /// </summary>
        public int TotalCount { get; private set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; private set; }

        /// <summary>
        /// 数据信息
        /// </summary>
      //  public List<T> Source { get; private set; }


        public  PagedList(List<T> source, int pageIndex, int pageSize, int totalCount)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = totalCount;
            TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
            this.AddRange( source.Take(source.Count));
        }
        public  PagedList()
        {}
        /// <summary>
        /// 是否包含上一页
        /// </summary>
        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 1);
            }
        }

        public bool HasNextPage
        {
            get
            {
                return (PageIndex  < TotalPages);
            }
        }
    }
}


标签:set,get,int,private,public,mvc,net,PagedList
来源: https://blog.51cto.com/u_12718584/2843746