ASP.NET MVC Framework
The paper focuses on features of ASP.NET MVC framework that
make it easier to use than other existing frameworks. It also covers topics like
developer’s control over the application and unit testing.
The framework has
evolved with each of it previews and p
re release versions based on community
feedback. It is not meant as a replacement for the classic ASP.NET WebForms
framework but leverages a lot of the functionality and extensibility advantages
provided by it. Even if it is a new framework it is gaining p
opularity fast in the
.net developer community. A new version is of the framework is already on its
asp.net, mvc, framework
test driven development
ASP.NET MVC is a Microsoft product launched in April 2009 under Microsoft
It is now at the
second preview for version 2.0
Using ASP.NET MVC, developers can easily build web applications having full
control over views, enabling AJAX integration and making test driven development
MVC is not a replacement for WebForms. It actually works as an
extension for ASP.NET
The ASP.NET MVC framework fully supports existing
ASP.NET features like forms/windows authentication, URL authorization,
membership/roles, output and data caching, sessi
on/profile state management, health
monitoring, configuration system,
the provider architecture,
and many more.
As the name suggests, the framework relies on model view controller design pattern.
Coupling these three components makes
The model is responsible for maintaining the state. Very often, the state is kept in a
The view is responsible for displaying the application’s user interface.
The controller is used to handle end user interaction, to ma
nipulate the model and
finally to render the view to be displayed.
Damian Sorin, Ionel Ancuta
In a MVC application the view is onl
y about displaying information. I
t is the
controller that handles and responds to user input and interaction.
By default, ASP.NET MVC uses
regular .aspx pages to render the view. But since the
framework is made of interchangeable parts, different types of view engines can be
used (for examp
le, Spark, NVelocity, Brail
It is highly extensible and pluggable.
Everything in the MVC framework is
designed so that it can be easily replaced/customized (for example: you can optionally
in your own view engine, routing policy, parameter serialization, etc).
supports using existing dependency injection and IOC container models (Windsor,
ing.Net, NHibernate, etc).
It includes a very powerful URL mapping component that enables
applications with clean U
that don’t have extensions within them
designed to easily support SEO and REST
friendly naming patterns
replaced by methods
This is a core concept in ASP.NET MVC.
Working with WebForms implied that a
request was actually a request for a page
which was translated into HTML and then
served as response.
MVC’s case, the request is handled by a routing
which decides what controller and action to use. The actions are merely public
ey hand the control to the view which is rendered to HTML and
returned to the user.
h test units is easier due to separation of concerns, one of the
framework’s principles. “Mockable” components and their isolations help when it
comes to writing independent tests for a particular component.
Also, ASP.NET MVC
doesn’t use page lifecycle.
can unit test the application without having to run the Controllers
within an ASP.NET process (making unit testing fast).
ny unit testing framework
would work :
NUnit, MBUnit, MS Test,
and so on
ASP.NET MVC relies on a certain
amount of convention to reduce the amount of
configuration. One of these conventions regards naming of directories where
application’s views and controllers are kept. The ASP.NET MVC expects directories
“Views” and “Controllers” to exist. According to th
is naming convention, images
and CSS files should be placed in the “Content” directory
but this is not mandatory
Error! Use the
Home tab to apply title to the text that you want to appear here.
In order to make a simple but functional ASP.NET application, the following files
need to be added (taken from a starter ASP.NET MVC project):
HomeController view files (Index.aspx and About.aspx in the example)
Other optional directories (for ajax helpers, for example)
Some small changes in Web.config need to be done so that
for the site
to make the
uests to the ASP.NET MVC engine (each required assembly should be
referenced for compilation, a namespace refere
nce to system.web/pages section
should be added to allow access to System.Web.Mvc helpers, System.Linq and
System.Collections.Generic from the view page)
. The only required namespaces are
System.Web.Mvc and System.Web.Mvc.Html. The others are just helpful.
Registering the UrlRoutingModule HttpModule is mandatory because this is the
module responsible for matching the URL requested to the proper route
Comparison with Zend Framework
Both ASP.NET MVC and Zend are frameworks based on model view controller
design pattern. They both simplify developer’s work by offeri
generated views, forms, validations, and so on.
They both offer a “default” directory structure which can be altered from
configuration files (Web.config, bootstrap)
, they have a routing engine that tells
which controller and action should
be considered next and
separation of concerns is a
principle enforced in both frameworks.
Other than that,
ASP.NET offers a stronger support when using databases: with
Linq to Sql there is no need to create models while Zend_Db imposes creation of
models and this may be considered a waste of time.
Limitations and future improvements
Amongst the improvements the second preview brought are the following:
ASP.NET MVC 2 includes the
jQuery validation library
side validation based on the model’s validation metadata.
using adaptors to change the client library is possible.
Preview 2 includes in
x support for single project areas for
developers who wish to organize their application without requiring multiple
projects. Registration of areas has also been streamlined
Model validation providers
: They allow
hooking in alternative validation logic to
provide validation when model binding. The default validation providers uses Data
: They allow
hooking in alternative sources of metadata for
model objects. The default metadata provider uses Data Annotations.
Professional ASP.NET MVC 1.0
, Rob Connery, Scott Guthrie, Phil Haack, Scott
Hanselman, Wiley Publishing, 2009
ASP.NET MVC in action
Jeffrey Palermo, Ben Schreiman, Jimmy Bogard,
Manning Publications, 2009