PaginatedList Helper


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public class PaginatedList<T> : List<T>
  2. {
  3. public int PageIndex { get; private set; }
  4. public int PageSize { get; private set; }
  5. public int TotalCount { get; private set; }
  6. public int TotalPages { get; private set; }
  7.  
  8. public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
  9. {
  10. PageIndex = pageIndex;
  11. PageSize = pageSize;
  12. TotalCount = source.Count();
  13. TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
  14.  
  15. this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
  16. }
  17.  
  18. public bool HasPreviousPage
  19. {
  20. get
  21. {
  22. return (PageIndex > 0);
  23. }
  24. }
  25.  
  26. public bool HasNextPage
  27. {
  28. get
  29. {
  30. return (PageIndex + 1 < TotalPages);
  31. }
  32. }
  33. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.