Introduction
In this article, we will understand what Model, View, and Controller (MVC) is and create a simple application using it.
Model View Controller
MVC is a software architecture, which separates the logic from the user interface. This is done by separating the application into three parts Model, View, and Controller. MVC is the separation of concern. MVC is also a design pattern.
Model
Represents the logical behavior of data in the application. It represents applications business logic. The model notifies the view and controller whenever there is change in state.
View
Provides the user interface of the application. A view is the one that transforms the state of the model into readable HTML.
Controller
Accepts inputs from the user and instructs the view and model to perform the action accordingly.

Advantages of MVC
- Full control over HTML rendered. No renaming of HTML IDs
- Provides a clean separation of concerns (SoC).
- No ViewState (Stateless).
- Enables Test Driven Development (TDD).
- Easy integration with JavaScript frameworks.
- RESTful URLs that enable SEO. Representational state transfer URLs example User/Comment/1, which is user-friendly, with no URL rewriting required.
- Integration on the client side becomes easy like using JavaScript, jQuery, Ajax, and JSON….
- Supports multiple view engines (aspx, Razor)
Creating a simple application
Step 1. From the file menu select Project and select MVC 4.0 application.

Step 2. Select the template and view engine (Razor, ASPX, NHaml, and Spark). To include a test project check the option "Create unit test project":

A solution with the following structure is added.

Build and run the application, and you will see the home page of the application. By default, we have the Home, About and Contact sections added.

Let's add our own Controller, Model, and View for showing the User's details. Right-click on Model and add a class with the name UserModels.cs with the following structure.

Now let's apply validations on the fields.

- Required: To make the field value mandatory.
- StringLength: To set the maximum length of the field.
- Range: To set the minimum and maximum value.
- DataType: To set the type supported by the field.
Let's add some default data to our view. For that, we will create a class called user and initialize with some default value.

Now let's add methods for adding, updating, and getting the list of all users.









Shambhoo KumarPosted Dec 5, 2014, 4:34 AM
Really doing nice work dear, i appreciate your work, keep it up. http://www.solutionforpcthreats.blogspot.in
alpa sarupriaPosted May 20, 2014, 8:48 AM
plz share me your other articles on mvc also
Nandkishor IngavalPosted Jun 12, 2013, 10:12 AM
Nice articals
lalita pophalePosted Apr 30, 2013, 6:58 AM
Excellent article to start asp.net MVC4 with razor Thanks for sharing.
Rohatash KumarPosted Nov 8, 2012, 3:37 AM
Excellent article, To start asp.net mvc application. Thanks
Dorababu MekaPosted Nov 8, 2012, 12:27 AM
Crystal clear explanation, expecting more MVC articles from you Anuja Pawar
David BallackPosted Nov 7, 2012, 10:15 PM
Nice way to create simple application using MVC. Thanks for sharing.
Varesh TuliPosted Nov 7, 2012, 10:09 PM
Nice article, thanks for sharing.