我用的分页类public class PaginatedList<T> : List<T>
{ public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; } public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
} public bool HasPreviousPage
{
get
{
return (PageIndex > 0);
}
} public bool HasNextPage
{
get
{
return (PageIndex + 1 < TotalPages);
}
}
}数据显示:public ActionResult Answer(int? page,int id)
{
const int pageSize = 1; var question = qar.FindUpcoming(id);
if (question != null)
{
var paginatedquestion = new PaginatedList<QAnswer>(question, page ?? 0, pageSize); return View(paginatedquestion);
}
else
return View("NotFound");
}每页只显示1条数据,显示出来的数据就是没有数据库中的第一条数据
我该怎么改页面才会显示正常,希望高手指点,在线=
{ public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; } public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
} public bool HasPreviousPage
{
get
{
return (PageIndex > 0);
}
} public bool HasNextPage
{
get
{
return (PageIndex + 1 < TotalPages);
}
}
}数据显示:public ActionResult Answer(int? page,int id)
{
const int pageSize = 1; var question = qar.FindUpcoming(id);
if (question != null)
{
var paginatedquestion = new PaginatedList<QAnswer>(question, page ?? 0, pageSize); return View(paginatedquestion);
}
else
return View("NotFound");
}每页只显示1条数据,显示出来的数据就是没有数据库中的第一条数据
我该怎么改页面才会显示正常,希望高手指点,在线=
非得写满才叫回答?
免费而且开源的