In this chapter, we’ll look at an ASP.NET MVC simple work example. We’ll build a simple web application here. In order to create an ASP.NET MVC application, we will use Visual Studio 2015, which includes all the features you need to create, test and deploy a MVC framework.

Create application for ASP.Net MVC

Below are the steps to create a project using the Visual Studio project templates.

Step 1 ? Open the Studio Visual and Click New File from menu option.

ASP.NET MVC Getting StartedStep 2 ? From left pane, then select Templates then Visual C# then Web.

Step 3 ? Then select ASP.NET Web Application.

Step 4 ? Enter the project name in the Name field, MVCFirstApp, and click OK to proceed. You will see the following dialog asking you to set the initial ASP.NET project content.

ASP.NET MVC Getting StartedStep 5 ? To keep things simple, select the option ‘Empty’ and check the MVC checkbox in the section Add folders and core references then click OK.

A basic MVC project with minimally predefined content will be created. Once Visual Studio has created the project, you ‘ll see a number of files and folders in the Solution Explorer window.

ASP.NET MVC Getting StartedSince you know that we have created an ASP.Net MVC project from an empty project template, there is currently nothing to run in the application.

Step 6 ? Run this application from the Start menu option for debugging and you will see a 404 error not found.

ASP.NET MVC Getting StartedThe default browser is Internet Explorer, but you can choose from the toolbar any browser you have installed.

Add Controller

To delete the error 404 Not Found, we must add a controller that handles all incoming requests.

Step 1 ? To add a controller, right – click the controller directory in the solution explorer and select Add Controller.

ASP.NET MVC Getting StartedThe Add Scaffold dialog will be displayed.

ASP.NET MVC Getting StartedStep 2 ? Choose MVC 5 Controller–Empty option and click on ‘Add’.

ASP.NET MVC Getting StartedStep 3 ? Set the HomeController name and then click the Add button.

You ‘ll see a new HomeController.cs C # file in the Controllers folder that can also be edited in Visual Studio.

ASP.NET MVC Getting StartedStep 4 ? Let’s change the controller class by changing the action method called Index using the following code to make this a working example.

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 displays the index action method results.

ASP.NET MVC Getting Started