Posts Tagged 'RAD development'

How to: RAD ASP.NET MVC with MvcContrib

ASP.NET MVC has many obvious merits – testability, separation of concerns, RESTful URLs etc. But one thing it notoriously doesn’t have is much support for Rapid Application Development. You have complete control over HTML… at the cost of writing all the HTML yourself. With ASP.NET Web Forms you might struggle to take complete control over the HTML, but it provides an enormous amount of support for RAD via controls that write the HTML for you.

Wouldn’t it be nice if we could have something similar in ASP.NET MVC? That’s where MvcContrib comes in.

In an earlier post, I introduced you to MvcContrib’s TestHelper. Another useful feature it offers is an HTML helper that generates grids – removing all the tedious donkey-work of writing the HTML table yourself, and taking a big step in the RAD direction.

The first thing you need to do is download MvcContrib from codeplex and set a reference to it inside your project. That gives you access to the MvcContrib.Ui.Grid namespace, and the Html.Grid() method. Now you can create a grid without having to write all the HTML yourself.

First, create a controller method that passes a strongly typed IEnumerable to the View. Here is a controller method that retrieves a list of Game objects and passes them to the view:

method returning IEnumerable to a view

Your view should be strongly typed to the Model, and have a using/Imports statement for MvcContrib.UI.Grid:

strongly typed view with using statement

Then all you have to do is pass the Model to Html.Grid(), and use a Lambda expression to define the columns:

call to the Grid() method

This lays out a Grid. In this case it’s a very simple grid (essentially just a table), but with a little work you can add support for the more advanced Grid features you would expect from RAD controls, such as pagination, sortability and custom columns.

the resulting table

So there you have it – a form of RAD that’s available for ASP.NET MVC. It’s not drag-and-drop, but it is rapid, and a lot more productive than writing all your own HTML.

Kevin Rattan

For related information, check out these courses from Learning Tree:

Building Web Applications with ASP.NET MVC

Building Web Applications with ASP.NET and Ajax


Learning Tree International

.NET & Visual Studio Courses

Learning Tree offers over 210 IT training and Management courses, including a full curriculum of .NET training courses.

Free White Papers

Questions on current IT or Management topics? Access our Complete Online Resource Library of over 65 White Papers, Articles and Podcasts

Enter your email address to subscribe to this blog and receive notifications of new posts by e-mail.

Join 29 other followers

Follow Learning Tree on Twitter

Archives

Do you need a customized .NET training solution delivered at your facility?

Last year Learning Tree held nearly 2,500 on-site training events worldwide. To find out more about hosting one at your location, click here for a free consultation.
Live, online training

%d bloggers like this: