Why MVC?
Hello, In this sequence of Blogs we are going to understand: What is Purpose of MVC, What is architectural Pattern of MVC and Basic Understanding of MVC
Before I start MVC I like to discuss Why MVC is required.
The two needed things are reusability of a code behind logic and easiness of testing and maintainability.  1.0

The ASP.NET code behind is completely tied up with ASP.NET Httpcontext object which makes unit testing very difficult.

It is difficult to test the below behind ASP.NET code. How do I create a Http context object, how do I simulate the sender and EventArgs objects of the button clicks etc.


That’s where MVC comes to rescue. The behind code is moved to a simple .NET class called as controller. Any user request first comes to the controller class, the controller class then invokes the model and attaches the model to the view for display to the end user.


What is MVC ?


Everyone knows
C-Controller[Business Logic]

Getting Familiar with MVC 5 Application

In VS2015 I am creating ASP.NET web application with dot net framework 4.5 and inside this we will get MVC 5 templates
I prefer C sharp for this full learning


We will select MVC application template.
Single page application, Facebook and Web API templates are new in MVC 5
I don’t prefer to change authentication right now.


You can see we already have some ready made stuff with organized folder structure
We will see all step by step but right now without doing anything I just want you to run this application.


This Application is already with pre-defined template which looks very cool
We already have some authorization and authentication code associated with this
Some dummy about and Contact pages are also there for demo

Have a look at HomeController which is having three actions here


Every Controller connects with the view and mostly each action is going to connect with the particular.cshtml view as shown in snap


Obviously viewbag is somewhere used in this cshtml page
@ symbol will deal with c sharp code
Simply we have c sharp + html in single page


We have _Layout.cshtml which is located under shared folder and its holding common content of the UI
Simply I can compare this with masterpage of aspx UI
Actually it’s a partial view[I will cover it later]


We have global.asax file for global app specific configurations
This file is actually registering different codes which are actually located under App_start folder


While running this application you can notice that address bar is not showing a page with extension but its properly formatted as
And default is home/index


This is because of Routeconfig.cs
We can also define our own pattern of multiple routes


Leave a Reply

Your email address will not be published. Required fields are marked *