PagedList using LINQ Skip and Take, but show paging using Count of results

前端 未结 5 1285
眼角桃花
眼角桃花 2020-12-15 06:02

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

5条回答
  •  Happy的楠姐
    2020-12-15 06:25

    You will still likely have to ask for a count separately.

    var products = repository.Products
                             .Where(p => this.CurrentCategory == null || p.Category == this.CurrentCategory);
    var numProds = products.Count();
    var mypage = products.OrderBy(p => p.ProductID)
                         .Skip((page -1) * PageSize)
                         .Take(PageSize);
    

提交回复
热议问题