/ Published in: C#
Action method to send Paginated results using PetaPoco and MvcContrib to a view
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public ActionResult Index(int? page) { //Normally, with a big ORM, using AsPagination to lazy Paginate would work fine. //but it's in-efficient to do this using PetaPoco //var pagedList = Db.Query<SomeModel>("").AsPagination(page ?? 1, 10); //...so we'll do it the PetaPoco way for efficient results var dbPage = Db.Page<SomeModel>(page ?? 1, 10, ""); //see if the Db really ran effient sql Trace.Write(Db.LastCommand, "SQL to get resulsts"); //Instead of AsPagination, CustomPagination works, providing "TotalItems" param dbPage.Items, (int)dbPage.CurrentPage, (int)dbPage.ItemsPerPage, (int)dbPage.TotalItems); return View(viewModel); }