Return to Snippet

Revision: 54691
at January 7, 2012 09:26 by dkitchen


Initial Code
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
            var viewModel = new CustomPagination<SomeModel>(
                dbPage.Items,
                (int)dbPage.CurrentPage,
                (int)dbPage.ItemsPerPage,
                (int)dbPage.TotalItems);

            return View(viewModel);
        }

Initial URL

                                

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

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

Initial Tags

                                

Initial Language
C#