MvcContrib Grid

One of my favorite controls available in the MvcContrib is the Grid component.

I’ve been using it for quite awhile.  They have decided to rewrite, but thankfully they include the older grid for legacy purposes  – which will allow me to refactor and take advantage of the new grid.

Information on the new Grid – documentation for it – can be found here:

http://www.jeremyskinner.co.uk/2009/02/08/rewriting-the-mvccontrib-grid/

It’s built using a nice fluent interface style:

ie.

<%= Html.Grid(Model.People).Columns(column => {
     		column.For(x => x.Id).Named("Person ID");
     		column.For(x => x.Name);
     		column.For(x => x.DateOfBirth).Format("{0:d}");
     	})
        .Attributes(style => "width:100%")
     	.Empty("There are no people.")
     	.RowStart(row => "<tr foo='bar'>") %>

 

It has paging support as well:

<%= Html.Grid(Model.People).Columns(column => {
     		column.For(x => x.Id).Named("Person ID");
     		column.For(x => x.Name);
     		column.For(x => x.DateOfBirth).Format("{0:d}");
}) %>   <%= Html.Pager(Model.People) %>

All of this information can be found at the link above.

As per the release page of MvcContrib, if you have been using the previous Grid, you can reference it’s new namespace:

The original grid has been moved to the MvcContrib.UI.LegacyGrid namespace and will continue to function as before. The new grid is located in MvcContrib.UI.Grid

This will look like the following in your web.config:

<add namespace="MvcContrib"/>

<add namespace="MvcContrib.UI.Html"/>

<add namespace="MvcContrib.UI.Grid"/>

<add namespace="MvcContrib.UI.LegacyGrid"/>

(And by the way: definitely add namespaces in the web.config vs. the individual pages !  YAGNI lol)

Advertisements

One thought on “MvcContrib Grid

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s