Action method to send Paginated results using PetaPoco and MvcContrib to a view


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

Action method to send Paginated results using PetaPoco and MvcContrib to a view


Copy this code and paste it in your HTML
  1. public ActionResult Index(int? page)
  2. {
  3. //Normally, with a big ORM, using AsPagination to lazy Paginate would work fine.
  4. //but it's in-efficient to do this using PetaPoco
  5. //var pagedList = Db.Query<SomeModel>("").AsPagination(page ?? 1, 10);
  6.  
  7. //...so we'll do it the PetaPoco way for efficient results
  8. var dbPage = Db.Page<SomeModel>(page ?? 1, 10, "");
  9.  
  10. //see if the Db really ran effient sql
  11. Trace.Write(Db.LastCommand, "SQL to get resulsts");
  12.  
  13. //Instead of AsPagination, CustomPagination works, providing "TotalItems" param
  14. var viewModel = new CustomPagination<SomeModel>(
  15. dbPage.Items,
  16. (int)dbPage.CurrentPage,
  17. (int)dbPage.ItemsPerPage,
  18. (int)dbPage.TotalItems);
  19.  
  20. return View(viewModel);
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.