Use MvcContrib Grid to Display a Grid of Data in ASP.NET MVC

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
The past six articles in this series have looked at how to display a grid of data in an ASP.NET MVC application and how to implement features like sorting, paging,
and filtering. In each of these past six tutorials we were responsible for generating the rendered markup for the grid. Our Views included the
Code:
<table>
tags, the
Code:
<th>
elements for the header row, and a
Code:
foreach
loop that emitted a series of
Code:
<td>
elements for each row to display in the grid. While this approach certainly works, it does lead to a bit of repetition and inflates the size
of our Views.

The ASP.NET MVC framework includes an http://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.aspx
Code:
HtmlHelper
class that adds support
for rendering HTML elements in a View. An instance of this class is available through the
Code:
Html
object, and is often used in a View to create action links
(
Code:
Html.ActionLink
), textboxes (
Code:
Html.TextBoxFor
), and other HTML content. Such content could certainly be created by writing the markup by hand
in the View; however, the
Code:
HtmlHelper
makes things easier by offering methods that emit common markup patterns. You can even
http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs create your own custom HTML Helpers by adding
http://www.4guysfromrolla.com/articles/120507-1.aspx extension methods to the
Code:
HtmlHelper
class.
http://mvccontrib.codeplex.com/ MvcContrib is a popular, open source project that adds various functionality to the ASP.NET MVC framework. This includes
a very versatile http://mvccontrib.codeplex.com/wikipage?title=Grid Grid HTML Helper that provides a strongly-typed way to construct a grid in your
Views. Using MvcContribs Grid HTML Helper you can ditch the
Code:
<table>
,
Code:
<tr>
, and
Code:
<td>
markup, and instead use
syntax like
Code:
Html.Grid(...)
. This article looks at using the MvcContrib Grid to display a grid of data in an ASP.NET MVC application. A future installment
will show how to configure the MvcContrib Grid to support both sorting and paging. Read on to learn more!

http://www.4guysfromrolla.com/articles/031611-1.aspx" class="readmore Read More >

View the full article
 
Back
Top