I wish you all
a very Happy New Year to you & your family. I am glad to start my first article on New Year. In this
tutorial series, we are going to understand all about ASP.NET MVC.
Let’s begin here to bring you a lucid picture on what is MVC, why this came into picture, what are the advantages of MVC, will this be advantageous and how different is this over the existing system, etc., Good, if you already know this. If not, I hope you would become thorough once after going through this article.
Before we step in to our ASP.NET MVC, let me clear out the lice poking your mind. Straight to the point,
What are the pitfalls in the existing system ASP.NET Web Forms, which led us to pave our way to ASP.NET MVC framework.
On Comparing with ASP.NET Web Forms:
The traditional ASP.NET works everything fine but it is more complicated
in reality. Overtime, in the Web Forms some of the aspects were highlighted as
1. View State Weight: View State is
nothing but a mechanism to maintain a state across the page requests. It
results in a large chunk of data to be transferring between the client and
server to maintain its state across requests. Sometimes, it may cross-high
amount of KB’s. It goes back and forth with each request. Thereby, it shows a
poor response on the page request as well as consumes more bandwidth.
2. Page Life Cycle: As part of the Page
life cycle, the mechanism for connecting client-side events with server-side
event handler code would be much more complicated to deal at runtime without
getting any view state errors. Some may even fail to execute.
3. False sense of Separation Of
Concerns: Though ASP.NET’s code behind class separates the application code
from User Interface HTML mark up, developers are encouraged to mix the
presentation code(server side control like GridView) and the logic(Data from
the database) within the code behind classes, which can be fragile and
4. Limited Control over HTML: Though the
Browser’s are compliant with HTML standards and render the server controls as
HTML web controls, sometimes it would be tricky to get the HTML we expect.
Prior to ASP.NET 4, the HTML output typically fails to comply with web
standards or make good use of CSS and even sometimes generates an unpredictable
pitfalls are reduced in ASP.NET 4.
5. Leaky Abstraction: Web forms tries to hide away HTML and HTTP
wherever possible. As you try to implement customer behaviors, you fall
out of the abstraction, which forces you to reverse engineer the post back
event mechanism or take obtuse acts to generate the desired HTML. wherever possible. As you try to implement customer behaviors, you fall out of the abstraction, which forces you to reverse engineer the post back
event mechanism or take obtuse acts to generate the desired HTML. Indeed ASP.NET abstracts away the difference between writing the HTML code to handle clicking on a hyperlink (<a>) and the code to handle clicking on a
6. Low Testability:
Unit testing being
the essential part of any software development, the tightly coupled web forms
architecture stands unsuitable for prefect Unit Testing.
Introduction & Advantage’s:
is an architectural pattern.
is a web development framework that combines the effectiveness of classic
ASP.NET along with MVC architectural pattern.
1. It gives you a powerful, patterns-based way to
build dynamic websites that enables “separation
of concerns” to manage complexity.
2. It includes the best parts of
existing ASP.NET and the most suitable for up-to-date techniques from “Agile Development” providing full
control over application behavior for large teams.
3. Emphasizing, it enables fast Isolated
TDD (Test Driven Development) which
declares it as a best alternative to Web Forms pattern for creating MVC based
web applications. Hence, ASP.NET MVC Framework can be titled highly testable
4. No concept of “ViewState” or Server based forms. All the server side controls
of UI can be replaced by simple HTML. No need of using viewState, postback’s to
create the effect of state fullness. Hence, ASP.NET MVC Framework is called light
5. It uses a Front Controller pattern
that processes Web application requests through a single controller that
provides you a rich routing infrastructure.
6. Defined in the fundamental supported
part of ASP.NET’s System.Web
namespace – System.Web.MVC
7. Can be easily replaced or customized,
extensible and pluggable framework. The Framework is built as a series of
independent components – as a .NET interface or built on an abstract base
class, so you can easily replace or plug in your URL Routing System, your own
View Engine, Controller factory, etc.,
You can use the default implementation of the component, OR
Derive a subclass to include its behavior OR
Change the component entirely with a new implementation of the interface or the
base class. Similar to Provider model of ASP.NET 2.0
8. Tight Control over HTML and HTTP
--> ASP.NET MVC recognizes the importance of producing clean, standards-compliant
markup. Its built-in HTML helper methods produce standards-compliant output.
For complicated UI’s, readymade widgets or libraries can be used. Hence, it is
so well compatible with the popular JQuery library and Microsoft does provides
jQuery as a built in part of the default ASP.NET MVC template and lets you
directly reference jQuery.js file on Microsoft’s CDN (Content Delivery
9. It gives a powerful Routing System
and User Friendly URL naming patterns for both Search Engine Optimization
(SEO), Representational State transfer (REST) and are user readable. URLs do
not need to include file-name extensions.
10. Modern API and ASP.NET MVC is open source. You
can free to edit and compile your own version. You can download it from http://aspnet.codeplex.com/
So, I hope this article is helpful.
In the further articles, we will see how the MVC framework looks like and its
application structure, walkthrough of its evolution & up gradation
including new features from its beta version, When to choose MVC pattern,etc.,