Wednesday, 21 September 2016

Chapter-2 Developing web Application Using Asp.Net MVC

Introduction to the MVC Development Platform

1)      The MVC development platform separates the application data, the presentation, and the flow of application, into three separate components:
i)        The model
ii)       The view
iii)     The controller
b)      The model:
i)        Manages the application data.
ii)       Encapsulates data stored in a database as well as code used to manipulate the data.
c)       The view manages the display of information.
d)      The controller:
i)        Manages the flow of application.
ii)       Handles user input.
iii)     Provides data to the relevant view.

Idea behind MVC 

Idea behind View is responsible for the user interface  that can be made by using HTML or UI widgets on desktop application.
View talk to model that model contains data which needs to display. In web application does not contains any code except HTML code ,client-side validation .
Controller organizer everything .When HTTP arrives from MVC application that request gets routed to a controller and then to their database ,file system, or model.

Note : - MVC development kit is included in Visual Studio 2012 ownwards.

You can also install MVC development Kit in Visual Studio 2010 from the below link

Microsoft provides a free version of Visual Studio, which also contains SQL Server and it can be downloaded from

Complete Steps How to Install Visual Studio MVC 2012

Step 1:  After completely downloading, You need to run the installer .

Step 2: Click on Install button .It will Start installing it.

Once the installation is complete below dialog box will show

Step 3: Click on restart you
Step 4: Open Visual Studio click on Start Menu
Once all done you will see the Main window of visual studio.

Create A Simple MNC Application

Step 1: Open the Visual Studion . Click on File ->New -> Project Menu option

Step 2: From the left pane, select Templates -> Visual C# -> Web.
Step 3: In the middle pane, select ASP.NET Web Application.
Step 4: Enter the project name, MVCFirstApp, in the Name field and click ok to continue.

Step 5: Select the ‘Empty’ option and check the MVC checkbox in the Add folders and core references section. Click Ok.
It will create a basic MVC project with minimal predefined content.
Once the project is created by Visual Studio, you will see a number of files and folders displayed in the Solution Explorer window.

As you know that we have created ASP.Net MVC project from an empty project template, so for the moment the application does not contain anything to run. 
Step 6: Run this application from Debug -> Start Debugging menu option and you will see a 404 Not Found Error.

Add Controller

To remove the 404 Not Found error, we need to add a controller, which handles all the incoming requests. 
Step 1: To add a controller, right-click on the controller folder in the solution explorer and select Add -> Controller.

It will display the Add Scaffold dialog.

Step 2: Select the MVC 5 Controller – Empty option and click ‘Add’ button.
The Add Controller dialog will appear

Step 3: Set the name to HomeController and click the Add button.
You will see a new C# file HomeController.cs in the Controllers folder, which is open for editing in Visual Studio as well. 

Step 4: To make this a working example, let’s modify the controller class by changing the action method called Index using the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVCFirstApp.Controllers
    public class HomeController : Controller
        // GET: Home
        public string Index()
            return "Hello World, this is ASP.Net MVC Tutorials";

Step 5: Run this application and you will see that the browser is displaying the result of the Index action method.
1)      Controllers are C# classes that contain methods. Each public method in a controller is known as an action method or a controller action.
2)      Microsoft provides a free version of Visual Studio, which also contains SQL Server and it can be downloaded from

I hope that the functionality of the above attribute is clear to you now. Now you can use this code in your application. If you have further question, just drop a line below and I will try to answer you as soon as possible.

Last but not least, connect with me on Twitter , Facebook , LinkedIn and Google+ for technical updates and articles news. We won’t spam or share your email address as we respect your privacy.

No comments:

Post a Comment