0

Using entity framework in asp.net MVC, i'd like to break a long list of query results to show on multiple pages/views, as an example suppose there are 30 product items returned from DB and now needs to distribute on 3 pages ( 10 records per page). what is the proper way to accomplish this requirement?

1 Answers1

0

Try Skip and Take on your query.

// get the second Page.
db.ProductItems.Where(p => p.ProductId == 1)
    .OrderBy(p => p.ItemPosition) // skip need at least one order by to work.
    .Skip(10).Take(10)
codeworx
  • 2,715
  • 13
  • 12