After having gone through
numerous of blogs and articles, I came to a conclusion that very few of the genuine
writers have explained the topic from the basic to full-fledged, while including a working application. My effort in this MVC articles series will be
to cover almost all the aspects of MVC starting from creating a simple app and
connecting with the database with various Microsoft providers. We’ll be
gradually moving forward part by part so we can understand and practically implement
All set? Let's start our
journey with Part1.
Part1: Introduction to MVC
architecture and Separation of Concerns
Topics to be Covered
- What does MVC mean.
- Understanding MVC
- Separation of Concerns
Model: The business entity on which the overall
application operates. Many applications use a persistent storage mechanism
(such as a database) to store data. MVC does not specifically mention the data
access layer because it is understood to be encapsulated by the Model.
View: The user interface that renders the model
into a form of interaction.
Controller: Handles a request from a view and updates
the model that results a change in Model’s state.
To implement MVC in .NET we
need mainly three classes (View, Controller and the Model).
The choice of MVC
comes when we go for a solution where the separation of concerns, ease of
maintainability and extensibility of an application matters a lot. As per the
architecture given below, we can see the request-response flow of a MVC
The architecture is self explanatory. The browser (as usual) sends a request to IIS, IIS searches for the route
defined in MVC application and passes the request to the controller as per route,
the controller communicates with the model and passes the populated model (entity)
to View (front end), Views are populated with model properties, and are rendered
on the browser, passing the response to browser through IIS via controllers
which invoked the particular View.
Separation of Concern
As per Wikipedia 'the process of
breaking a computer program into distinct features that overlap in
functionality as little as possible'. MVC design pattern aims to separate
content from presentation and data-processing from content. Theoretically sound,
but where do we see this in MVC? One place is reasonably clear - between the
data-processing (Model) and the rest of the application.
When we talk about Views and
Controllers, their ownership itself explains separation. The views are just the
presentation form of an application, it does not have to know specifically
about the requests coming from controller. The Model is independent of View and
Controllers, it only holds business entities that can be passed to any View by
the controller as required for exposing them to the end user. The controller is
independent of Views and Models, its sole purpose is to handle requests and
pass it on as per the routes defined and as per the need of rendering views. Thus
our business entities (model), business logic (controllers) and presentation
logic (views) lie in logical/physical layers independent of each other.
Now that we know why and where to
use MVC, in the next part of the series we’ll be creating an MVC application
from scratch, and exploring the practical implementation of MVC. For more informative articles,visit my blog A Practical Approach .
I am a C# Corner MVP,author,blogger and currently working as an Engineer Analyst in an MNC and have an experience of more than 6 years in C#.Net. I am a B.Tech in Computer Science and hold a diploma in Information Security and Application Development. My work experience includes Development of Enterprise Applications using C#,.Net and Sql Server,Analysis as well as Research and Development. I am a MCP in Web Applications(MCTS-70-528,MCTS-70-515) and .Net Framework 2.0 (MCTS-70-536). Please visit my blog A Practical Approach
for more informative articles.
Article of the Day on Microsoft's site http://www.asp.net/community/articles on 16 August 2013.
Article of the Day on Microsoft's site http://www.asp.net/community/articles on 28 August 2013.
Article of the Day on Microsoft's site http://www.asp.net/community/articles on 08 Sept 2013.
Article of the Day on Microsoft's site http://www.asp.net/community/articles on 29 Sept 2013.
Article of the Day on Microsoft's site http://www.asp.net/community/articles on 29 Oct 2013.
Member of the month for July 2013 on C# Corner
Month Winner for July 2013 on C# Corner