I am trying to display a filtered list of of products, based on Category filter and ItemsPerPage but I\'m having some issues when trying to use it with PagedList.
So
I had the exactly same problem and I ended up using StaticPagedList. You can do something like this
public ViewResult List(int page =1, string category =null)
{
if (category != null) this.CurrentCategory = category;
var products = repository.Products
.Where(p => this.CurrentCategory == null || p.Category == this.CurrentCategory)
.OrderBy(p => p.ProductID)
.Skip((page -1) * PageSize)
.Take(PageSize);
var count = repository.Products
.Where(p => this.CurrentCategory == null || p.Category == this.CurrentCategory).Count();
var resultAsPagedList = new StaticPagedList(products, page, PageSize, count);
return View(resultAsPagedList);
}
as for the view, you just need to replace the model type
@model StaticPagedList