Monday, January 10, 2011

My Grid Pt. 2: Building the Pager HTML Helper

This is the second part of a series of posts detailing how I built a pretty awesome ASP.NET MVC grid with support for sorting and paging.  For details about the model that will be bound to the grid, check out: My Grid Pt. 1: A Better Paged Collection.

Here is the reference picture of what I want the pager to look like:

image

As you can see, it consists of three parts:

  • Results information
  • Page size selector
  • Page selector

We’ll start with the page size selector.  This will be a private method that takes in the current page size and an optional integer suffix to append to the query string keys (in order to support multiple grids on one page).

Thursday, January 6, 2011

My Grid Pt. 1: A Better Paged Collection

I’d like to show you my pretty awesome ASP.NET MVC grid with support for sorting and paging.  But it’s a pretty big chunk of code, so I thought I’d start with the model that will be bound to the grid.

In his Nerd Dinner MVC app, ScottGu used a class he called PaginatedList<T> that inherited from System.Collections.Generic.List<T> and had some basic support for paging.  That was my starting point for my PagedCollection<T> class.