ASP.NET MVC ViewModel Pattern

This looks very similar to the recommended practice in the Wrox Professional ASP.NET MVC book, the first chapter of which is available for free from the above URL.

Starting on page 100 they have a section on ViewData and ViewModels.

When a Controller class decides to render an HTML response back to a client, it is responsible for explicitly passing to the view template all of the data needed to render the response. View templates should never perform any data retrieval or application logic – and should instead limit themselves to only have rendering code that is driven off of the model/data passed to it by the controller.

[…]

When using [the “ViewModel”] pattern we create strongly-typed classes that are optimized for our specific view scenarios, and which expose properties for the dynamic values/content needed by our view templates. Our controller classes can then populate and pass these view-optimized classes to our view template to use. This enables type-safety, compile-time checking, and editor intellisense within view templates.

Taken from “Chapter 1 “Nerd Dinner” from Professional ASP.NET MVC 1.0 written by Rob Connery et al published by Wrox”. The original is available at http://tinyurl.com/aspnetmvc

Leave a Comment