Posted By

dkitchen on 01/07/12


Tagged

MVC grid petaPoco mvcContrib


Versions (?)

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


 / Published in: C#
 

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

  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  

You need to login to post a comment.