I’ve got class named PagedList which looks like this:
public class PagedList<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 bool HasPrevious
{
get
{
return (this.PageIndex > 0);
}
}
public bool HasNext
{
get
{
return (this.PageIndex + 1 < this.TotalPages);
}
}
public PagedList(IEnumerable<T> source, int pageIndex, int pageSize)
{
this.PageIndex = pageIndex;
this.PageSize = pageSize;
this.TotalCount = source.Count();
this.TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
this.AddRange(source.Skip(this.PageIndex * this.PageSize).Take(this.PageSize));
}
}
In my Customers controller I use it like so:
public ActionResult Index(int? page)
{
IRepository<UserInfo> profile = ObjectFactory.GetInstance<IRepository<UserInfo>>();
const int pageSize = 25;
IQueryable<UserInfo> profiles = profile.GetAll().OrderBy(x => x.LastName).AsQueryable<UserInfo>();
var pagedCustomers = new PagedList<UserInfo>(profiles, page ?? 0, pageSize);
return View(pagedCustomers);
}
And finally in my Index.cshtml file I set up my Model like so:
@model System.Web.Mvc.ViewPage<PagedList<Clusteris.Data.UserInfo>>
And When I go Model. it’s a huge list, nothing to do with the PagedList I created in the Customers controller.
Anyone got any ideas on what I’m doing wrong?
UPDATE:
Screenshot:

PagedList is enumerable. To access individual UserInfo object use @foreach(var userInfo in Model)
Someone else mentioned about the use of IQueryable. It’s a good practice to use ToArray() or ToList() at boundaries. Your repository is a boundary, so I would consider moving the paging logic to it and make it return either the PagedList object or the data necessary to construct one.