Tag Archives: pagination

PetaPoco, MvcContrib Grid and Pagination

I’m using PetaPoco and MvcContrib in my current project.

I had a devil of a time finding a decent example of paging a grid in an efficient manner.

Here’s what I’ve got so far.

The Action should look like this:

——————— 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  dbPage = 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 efficient sql Trace.Write(Db.LastCommand, “SQL to get resulsts”); //instead of AsPagination use CustomPagination which provides a “TotalItems” param var viewModel = new CustomPagination<SomeModel>( dbPage.Items, (int)dbPage.CurrentPage, (int)dbPage.ItemsPerPage, (int)dbPage.TotalItems); return View(viewModel); } —————————-

@using MvcContrib.UI.Grid;

@using MvcContrib.UI.Pager;

@using MvcContrib.Pagination;

@model IPagination<SomeModel>


ViewBag.Title = “Some Stuff”;



Some Stuff to Page in a Grid</h2>

<div id=”grid”>



<div id=”pager”>

@Html.Pager(Model).First(“First”).Next(“Next”).Previous(“Prev”).Last(“Last”).Format(“{0}-{1} of {2}&nbsp;&nbsp;&nbsp;&nbsp;”)




Here is an extension method to wrap up the CustomPagination.

So now the action method can be a bit tighter

And the View needs to look a little something like this:

Hope that helps