Models, Views, and Controllers: ASP.NET MVC

The poor application programmer, chipping away contentedly in Winforms or Webforms, is often heard to groan whenever a new Microsoft product is announced. Silverlight (Groan), WPF (Groan), MVC (Groan) Hah! They caught you out there: what they have delivered with MVC is a design pattern, not a new technology, and it is free. The ASP.NET MVC 2.0 preview provides an interesting glimpse of how the ‘framework’ is developing.

It is good to see Microsoft get into the game of MVC architectures. Of course, there is nothing new about them; the technique of dividing the roles of an application into models, views, and controllers has been with us since the seventies. However, MVC gained a new relevance with web applications.

In any MVC design, such as Ruby on Rails, Monorail, Zend Framework, or Struts, the business logic is separated from input and presentation, with “Models” maintaining state. These models are responsible for maintaining the objects within the application and ensuring that they are represented in the relational database that underpins the application. A model will have “Views” associated with it. These Views, or projections, are the components needed to represent and display the model data in a way that the user can understand it and change it. “Controllers” manipulate the model, and respond to user input and interaction. When a model changes state, it notifies the views so they can reflect these changes.

This logical separation in application design makes a lot of sense with web design, though it works in a wide variety of information systems. The views become the rendered web pages, the controllers are the logical processes that happen in response to events and are enacted by scripting, and the models encapsulate the database entities and are maintained by the logical interface with the database.

Microsoft’s MVC implementation, within ASP.NET, aims to be as unobtrusive as possible. You can carry on using Webforms and Dynamic Data, and existing ASP.NET features continue to work exactly as expected, although URL Redirection may require some additional work if you have an existing mapping technique.

ASP.NET MVC 2.0 looks as if it is going to be most suitable for large-scale applications. The concept of ‘areas’, separate groupings of MVC triplets, is going to ease the task of testing and building the components of large applications by providing some isolation. It extends DataAnnotation rules for input validation. It introduces the Templated helper. In the pipeline is client validation, and the handling of asynchronous Controller Actions.

Is ASP.NET MVC worth learning? I’d say yes, if you’re the type of developer who wants full control over the application’s behavior, you’re engaged in a larger team development, and if you want a framework that is sympathetic to both TDD (Test-driven Development) and the separation of roles between developers and designers. However, it adds complexity, and lacks the rich event model and server controls of Web Forms. However, by their very nature, MVC architectures do not force you to adopt particular technologies: they’re there if you need them but you’re not forced to use them. If you like your applications lean and fast, then it is an approach that’s worth considering.

Let me know what you think, I’d be really interested to hear some other opinions.

Cheers,

Laila