Tip For Keeping ASP.Net MVC Views Easy To Read

Posted almost 3 years ago on June 24, 2009

ASP.Net MVC views are harder to read when they’re built with a lot of escapes between script and HTML, such as:

escapes

There’s really just no good way to make that easy to read using this approach.

Using the MVC Futures Repeater Control

Server controls and MVC just don’t sound like they’d go together, but if used for good I believe they can really serve a useful purpose. The following code snippet achieves the exact same result as above, but reads much cleaner:

repeater

The MVC Futures repeater control gives me a way to display repeating data with a template. The control is “bound” to the Model.Items collection because I set the name of the repeater to “Items”.

To get a reference to this control you need to include a reference to the MVC Futures assembly in the web.config:

reference

The complete solution with this code can be downloaded here:

Comments

mgroves writes...

Interesting, but what's the deal with the "Eval"s in there? I'd much rather see "item..About" than "Eval("About")". Is that possible?

June 24, 2009

Jon Kruger writes...

Yeah, but you lost your strongly typed-ness with that kind of binding.

June 24, 2009

New Comment