---
title: "First ASP.Net MVC 4 Application"  
description: "In this blog, I’m explaining how to create a simple asp.net mvc 4 application.  First you have to setup the development environment for asp.net mvc 4,"  
author: "Sumit Kesarwani"  
published: 2014-01-29  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/643/first-asp-dot-net-mvc-4-application  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 4 minutes  

---

# First ASP.Net MVC 4 Application

In this blog, I’m explaining how to create a simple [asp.net mvc](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) 4 application.\

First you have to setup the [development environment](https://www.mindstick.com/interview/34043/setting-up-a-development-environment-in-knockout) for asp.net mvc 4, for this you need [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2012 or Visual Studio 2010 with Service Pack 1. Once you have installed the visual studio, then you are ready to start creating asp.net mvc 4 application

##### Step 1

Start the Visual Studio 2012 and click on File -> New -> Project.

Select the ASP.net MVC 4 Application and give it the name “FirstMvcApp” and click on OK.

\
![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/6af2adb5-5798-4f54-8700-7d587ecbfbc7.png)

##### Step 2

The next dialog comes to select the project template:

![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/3b120935-249f-4930-9dec-f9b031f2edee.png)

Select the “Empty” project template and in [View Engine](https://www.mindstick.com/forum/155781/what-is-razor-view-engine-in-asp-dot-net-mvc) – select the “Razor” and click on OK.

##### Step 3

##### Adding your first controller

In MVC architecture, incoming requests are handled by controllers. In ASP.NET MVC, controllers are just simple [C# classes](https://www.mindstick.com/forum/158923/what-is-the-role-of-constructors-in-c-sharp-classes-and-how-are-they-different-from-regular-methods) (usually inheriting from System.Web.Mvc.Controller, the framework’s built-in controller [base class](https://www.mindstick.com/blog/116/base-class-initilization)). Each public method in a controller is known as an [action method](https://www.mindstick.com/forum/160300/how-to-pass-data-to-an-httppost-action-method-in-a-dot-net-core-api), meaning you can invoke it from the Web via some URL to perform an action.

To add the controller to [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project), right click the Controller folder in the Visual studio solution explorer like this:

\

![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/77f4126f-e1da-4dee-b582-c888ad1fc533.png)

When you click on controller a dialog appears:

![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/4c4e8804-a5cb-4bd0-96cc-0b5f5eb60283.png)

Enter the controller name as “HomeController” and in Scaffolding options select Empty [MVC Controller](https://www.mindstick.com/forum/12890/how-can-asp-dot-net-mvc-controller-return-an-image) and click on OK.

Visual Studio will open the HomeController.cs for editing and the default contents will look like this:

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace FirstMvcApp.Controllers{    public class HomeController : Controller    {        //        // GET: /Home/        public ActionResult Index()        {            return View();        }    }}
```

If you run the application at this point, you can see an error is generated that is [MVC Framework](https://www.mindstick.com/interview/34199/what-is-the-difference-between-forms-authentication-in-asp-dot-net-web-forms-and-asp-dot-net-mvc-framework) is not able to find the view like this:

\
![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/0dcce310-5e7a-435b-a359-b20c79a59837.png)

Actually this error is quite helpful; it explains not only that MVC could not find a view for our action method, but it shows where it looked. This is another nice illustration of an MVC convention: views are associated with action methods by a naming convention. Our action method is called Index and our controller is called Home and you can see from Figure 2-8 that MVC is trying to find different files in the Views folder that have that name.

##### Step 4

To create a view, stop the debugger and right-click the action method in the HomeController.cs code file (either on the method name or inside the method body) and select Add View from the pop-up menu.

\

\
![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/ae00e97e-dae1-481e-9bc2-136578583ba1.png)

A dialog will appear like this:

\

\
![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/aae5e0c2-f7d6-4c07-abad-e484fc924523.png)\

Give view name as “Index” and View Engine as “Razor (CSHTML)” and click on “Add” button, Visual studio open the Index.cshtml for editing and the default content look like this:

```
@{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title></head><body>    <div>            </div></body></html>
```

##### Expression

```
@{    Layout = null;}
```

This is an expression that will be interpreted by the Razor view engine. This is a pretty simple example. It just tells Razor that we chose not to use a master page. We are going to ignore Razor for the moment.

##### Step 5

Add a simple line in the body section:-

```
@{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title></head><body>    <div>        <h3>This is first asp.net mvc 4 application</h3>    </div></body></html>
```

And run the application:

![First ASP.Net MVC 4 Application](https://www.mindstick.com/blogs/72b87f40-8977-49d3-b27c-d4992ffa963c/images/59a118b9-12e9-4479-9038-57818ceca418.png)

---

Original Source: https://www.mindstick.com/blog/643/first-asp-dot-net-mvc-4-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
