MVC

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.

2.0

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.

3.0

What is MVC ?

4.0

Everyone knows
M-Model[Data]
V-View[UI]
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

5.0

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.

6.0

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.

7.0

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

8.0
Have a look at HomeController which is having three actions here

9.0

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

10.0

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

11.0

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]

12.0

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

13.0

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

14.0

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

15.0

Leave a Reply

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