Table of Contents
- Abstract
- Introduction to MVC
- Why MVC?
- ASP.NET MVC over ASP.NET Web-Forms
- Overview of Model View Controller
- What is a Model?
- What is a View?
- What is a Controller?
- Overview working of MVC
- Overview of routes collection
- What is route?
- What happened at runtime?
- Conclusion
- Special thanks to the audience
Abstract
In this article, we will discuss what was presented in the session for ASP.NET in Delhi Developer's day held on November 15, 2014.
It was an awesome event where all developers united under a common platform. All enjoyed and tried to explore their knowledge of ASP.NET MVC.
In this session, we covered the very basics of ASP.NET MVC, that is a very important build foundation of the ASP.NET MVC framework.
Here are the topics we covered in this session:
- Introduction to MVC.
- Why MVC.
- Reason to choose MVC against ASP.Net web forms.
- Overview of Model View Controller.
- Overview working of MVC.
- Overview of routes collection.
- Revisiting session.
- Question / Answer / Suggestion.
Introduction to MVC
A background to ASP.Net MVC:
- Based on ASP.Net.
- A framework for Rapid Application Development (RAD), used to develop Web applications.
- Is a composition of Model, View and Controller.
Is an open source and the code is available in Code Plex (In 2009 it was released under the Microsoft Public License and in 2012 it was released under the Apache License 2.0).
We can simply say that ASP.NET MVC is a framework that provides us the ability to create a web project, web application (called Rapid Application Development (RAD)).
Why MVC
Take a moment and think about the valuable Software Pattern Model-View-Controller. We can also predicts from the image that the MVC pattern divides a software application into three interconnected parts/components. Basically, it's a concept of separation (here just separation of internal representation of information from ways/logics/techniques how it is being represented to the end-user).

FIGURE 1: DEFINING MVC
As in the preceding image, let's elaborate on Model View Controller (MVC).
A Controller can send commands/directions to the model to update its state as well as commands to the view.
Associated views and the controller are notified by the Model as in changes of its state.
The Model provides a specific result as an output upon the request of the View to represent:

FIGURE 2: DEFINING MVC
Let's understand this from the above associated image.
In simple words, we can say that MVC is providing a facility to make our layers separate that are separated and interacting with each other.
ASP.NET MVC over ASP.NET Web-Forms
There are numerous reasons to choose ASP.Net for web development over ASP.Net Web Forms:
- ASP.Net MVC is a web framework and is based on the MVC pattern.
- No view state (performance is better in ASP.Net MVC).
- Completely testable.
- Integration with the client side (easily handshakes with client-side scripting like jQuery and so on).
Flexibility (provides various view engines that render HTML; Razor View Engine is the most famous).
Let's think of a scenario where we are writing an application in ASP.NET Web Forms. There are two classes for one thing. Let's say a default page that includes Default.aspx and Default.aspx.cs pages and our designer page.
A designer page has all the server control and aspx pages, that contain visualization of our server controls (UI part) and finally our cs page (class) contains all the functionality and other logic. Our class is based on an ASP.NET Page lifecycle (for complete details refer to: ASP.NET Page Life Cycle Overview).
We can't completely test our Web-Forms. To make it properly testable at some instance, we need to implement some other UI Design pattern such as MVP, MVVM or MVC.
If we are implementing the MVC UI Pattern to our Web Forms then why don't we use the ASP.NET MVC framework that already uses this pattern and provides everything required to create web apps?
Overview of Model View Controller
"This section of the session was a part of great discussion, what we learned until now. Please comment in this article what we discussed (all queries and so on). I'll update this section later."
Here is the conclusion that we discussed (for the ASP.Net MVC framework).
Models
- A MVC Model is typically a class (of C# or VB.NET).
- Both the controller and view can access the Model.
- A Model can be used to pass data from a Controller to the View.
- The main purpose of a View is to display the data in a page using the Model.
Views
- A View is nothing but a page, you can say a web page, and it does not have code-behind
- All page specific HTML generation and formatting can be done inside the View
- A request to the View can be made only from a Controller's action method
Controllers
- A Controller is typically a class (of C# or VB.Net) and inherits “system.mvc.controller”.
- Within this class, methods can be implemented and are called action methods. These are responsible for responding to the browser and/or calling the Views.
- The Controller class can access and use the Model class to pass data to the Views.
Overview working of MVC
In the following we will explore MVC more:

FIGURE 3: REQUEST RESPONSE
High level overview says: the browser sends a request to ASP.Net MVC and it returns a response back to the browser (the request is a HTTP request and the response is a HTTP response).

FIGURE 4: WORKING OF ASP.NET MVC
In a broader way: The first request comes to the Route Tables then passes to a specific controller before interaction with the Model Binding. It goes through Authentication and Authorization and afterwards fires a specific Action Method and executes the results to the View.
Overview of routes collection
In simple words, the routes collection (we also can say Route table) is nothing but a collection of routes.
Routes
A system works on a pattern matching mechanism. A route matches an incoming request to meet a specific pattern and allows once matched else denied.
What happens at runtime
At runtime, the routing engine uses a route table (contains various routes) to match incoming URLs with the defined route patterns (URL patterns).

FIGURE 5: ROUTE COLLECTION
In the above image, the URL will be processed if any match is found else it will throw the HTTP Status code Not Found (404 error).
Example of typical route collections:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Conclusion
In this very first session, we covered: ASP.Net MVC Series For Beginners: Part 1
- Basics of MVC
- Discussed MVC pattern
- Discussed basics of MVC architecture
- Discussed basics of route collection / route table

Shrivallanh DavalbhaktPosted Oct 9, 2018, 1:21 AM
Nice Article
Vikash TiwariPosted May 1, 2017, 5:14 AM
Nice Article about Mvc
kalu singh raoPosted Jul 7, 2016, 1:40 AM
Nice...
Thiruppathi RPosted Jun 3, 2016, 2:46 AM
Great Sharing..
Pawan TiwariPosted Apr 13, 2016, 5:16 AM
Thanks Gaurav. I have a suggestion that you should include hyperlinks of other article of same series in every article It will be better to find other articles as well as. Thanks
Mahdi Al AradiPosted Mar 6, 2016, 1:58 AM
In case the application is talking to DB, in terms of querying some data . In this case where will be placed these codes, i can see that MVC solves some issue with UI but decrease visibility of code behind . Any clue Gauray
Navratna PawalePosted Feb 19, 2016, 9:06 AM
great..
viral patelPosted Jan 29, 2016, 6:27 AM
nice post sir
Anu VPosted Oct 28, 2015, 6:06 AM
Good post for beginners..
Upendra Pratap ShahiPosted Oct 18, 2015, 6:56 AM
nice sir..
Gaurav Kumar AroraPosted Aug 16, 2015, 5:17 AM
Thanks Prakash Joshi
Purvi ThakkarPosted Aug 11, 2015, 1:26 AM
Nice article, where can i find part-2? which link?
Arjun DhilodPosted Jul 16, 2015, 6:36 AM
Really dam good keep it up but if i want to lean more what is next path of it
Shuby AroraPosted Feb 5, 2015, 2:34 PM
Prakash Joshi - it seems you missed the session it has been explained in the session this happened when view directly collaborating with Model. Gaurav Kumar Arora stated an update page example.
Prakash JoshiPosted Feb 5, 2015, 1:10 AM
Gaurav Kumar Arora sir in Figure 4 Model binding is written before Action methods. I have a confusion that how model binding can done before controller's action methods are called. As you have written in the paragraph (In a broader way) -- It goes through Authentication and Authorization and afterwards fires a specific Action Method and executes the results to the View. What I think is that the Controller's Action methods are called first then model binding is done. Please correct me if I am wrong.
Hamid KhanPosted Feb 1, 2015, 10:44 PM
Thanks
Gaurav Kumar AroraPosted Dec 30, 2014, 2:08 PM
During second session of the series @ December28, 2014. I received many questions related to basics of ASP.NET MVC, I am going to update this article with all those question/answers. Once again, I thanks to all great audience to make one more event successful.
Shuby AroraPosted Dec 18, 2014, 11:47 AM
@Vital wadje - this is not a concern to make article as featurefeatured. What I proposed articles which are related to chapter events should be featured. All decision is of csharpcorner team.
Vithal WadjePosted Dec 16, 2014, 6:42 AM
regarding your and some reader concern why this article is not featured ,i personally think that only those articles are become featured which are unique and new means something innovative,its my personal view because in last near about three year i have 2 featured articles.. but still your article is outstanding ,its helping other rather than featured is very important its my personal view
Gaurav Kumar AroraPosted Dec 16, 2014, 6:37 AM
Sumit Jolly - Thanks
Gaurav Kumar AroraPosted Dec 16, 2014, 6:36 AM
Vithal Wadje its all because of great readers, thanks
Vithal WadjePosted Dec 15, 2014, 11:38 PM
32482 + k views in just one month !...just outstanding ...keep it up
Guest UserPosted Dec 15, 2014, 7:32 PM
Gaurav Kumar Arora Shuby Arora i'll talk to team about this. But Gaurav is doing amazing job! Keep it up.
Gaurav Kumar AroraPosted Dec 15, 2014, 9:09 AM
Shuby Arora - thanks for reminder, I CC'ing again all members Sumit Jolly of Csharpcorner team Praveen Kumar @Manish T @Dinesh. I am sure these are pending with decision whether they will mark all session articles as Featured article or not?
Gaurav Kumar AroraPosted Dec 13, 2014, 4:03 AM
abhisek thakur what kind of improvement you want and lets have a discussion about this.
abhisek thakurPosted Dec 10, 2014, 8:14 AM
please tell me how to improve my programming
Syed BilalPosted Dec 5, 2014, 5:57 AM
This Article is very informative
Syed BilalPosted Dec 5, 2014, 5:56 AM
Nice Article...
Gaurav Kumar AroraPosted Nov 29, 2014, 2:23 AM
Manish Kumar Choudhary - glad to know that you liked this post
Manish Kumar ChoudharyPosted Nov 27, 2014, 12:11 AM
Nice one Gaurav Arora sir..
Ismail Hakki SenPosted Nov 24, 2014, 10:40 PM
following...
Shuby AroraPosted Nov 19, 2014, 12:45 PM
Thanks. @Praveen Kumar ji
Gaurav Kumar AroraPosted Nov 18, 2014, 4:48 AM
manish mittal thanks, glad to read that you liked this
manish mittalPosted Nov 17, 2014, 10:50 PM
Thank you for giving us a good platform. we are keen on to join Second section "ASP.Net MVC Series For Beginners: Part 2".
Guest UserPosted Nov 17, 2014, 9:00 PM
Shuby Arora I'm CCing C-Sharp Corner editorial team on your question? Manish Tewatia Praveen Kumar . Team please reply
Shuby AroraPosted Nov 17, 2014, 1:02 PM
Why this article is not marked as feature article. I believe all articles which are related to Developer's day sessions, should be marked as feature articles. CC: Sumit Jolly, @mahesh-chand, Gaurav Arora
Shuby AroraPosted Nov 17, 2014, 1:00 PM
Great article. Good contents and like the way how you presented
Gaurav Kumar AroraPosted Nov 17, 2014, 4:51 AM
mani k - so nice of you. I glad to know that and same here.. Definitely we will see more additional things in Part-2. Currently, I am waiting for audience comments so, I can prepare for Part-2
Mani KPosted Nov 17, 2014, 3:34 AM
Thank you for this excellent article We are waiting for "ASP.Net MVC Series For Beginners: Part 2"
Vithal WadjePosted Nov 17, 2014, 1:53 AM
great start
mehdi ahmadiPosted Nov 17, 2014, 1:20 AM
thanks , Where run action method? in controller or in Model
Guest UserPosted Nov 16, 2014, 9:25 PM
nice detailed article
Jeetendra GundPosted Nov 16, 2014, 1:25 PM
Great explanation sir...