Sometimes it's just nice to get some free snippet code. Increases understanding if used right, speeds up coding if used wrong.

Enabling paging on a controller action
public class HomeController : Controller
{
    [Paging]
    public ActionResult Index() { return View(); }
}

It really is as easy as that. Using the Paging attribute on the action creates a shared Paging in ViewData that can be used to page an arbitrary list.

Paging a list in the view (Razor)
@model IEnumerable<MyObject>
@foreach (MyObject in this.GetPage(Model))
{
    <div>@MyObject.SomeProperty</div>
}
<div>
    @Html.RenderPagination()
</div>

this.GetPage is an extension method on the Page object that performs the pagination and sorting on the IEnumerable<>

Last edited Mar 31, 2011 at 3:32 PM by cmbijpost, version 8

Comments

No comments yet.