mvc 分页构造函数使用
我要用到下边这个构造函数, 下边IEnumerable < Library > docList 写法有问题,该怎么写
List<Library> docList = 已经分好页的数据;
PagedList<Library> list = PagedList(IEnumerable < Library > docList, pageNo, 20, 100);
public PagedList(IEnumerable<T> items, int pageIndex, int pageSize, int totalItemCount)
{
AddRange(items);
TotalItemCount = totalItemCount;
CurrentPageIndex = pageIndex;
PageSize = pageSize;
}
/*
ASP.NET MvcPager 分页组件
Copyright:2009-2011 陕西省延安市吴起县 杨涛\Webdiyer (http://www.webdiyer.com)
Source code released under Ms-PL license
*/
using System;
using System.Collections.Generic;
namespace Webdiyer.WebControls.Mvc
{
public class PagedList<T> : List<T>,IPagedList
{
public PagedList(IList<T> items, int pageIndex, int pageSize)
{
PageSize = pageSize;
TotalItemCount = items.Count;
CurrentPageIndex = pageIndex;
for (int i = StartRecordIndex - 1; i < EndRecordIndex; i++)
{
Add(items[i]);
}
}
public PagedList(IEnumerable<T> items, int pageIndex, int pageSize, int totalItemCount)
{
AddRange(items);
TotalItemCount = totalItemCount;
CurrentPageIndex = pageIndex;
PageSize = pageSize;
}
public int CurrentPageIndex { get; set; }
public int PageSize { get; set; }
public int TotalItemCount { get; set; }
public int TotalPageCount { get { return (int)Math.Ceiling(TotalItemCount / (double)PageSize); } }
public int StartRecordIndex { get { return (CurrentPageIndex - 1) * PageSize + 1; } }
public int EndRecordIndex { get { return TotalItemCount > CurrentPageIndex * PageSize ? CurrentPageIndex * PageSize : TotalItemCount; } }
}
}