Create an Asp.Net Mvc Project using Visual Studio

In this post, I will show how to create an asp.net MVC 4.0 project using Visual Studio 10 SP1. The built in templates in Visual Studio makes it easy to start creating the application. In the screenshot below, I have opened Visual Studio, and creating a new MVC 4.0 project using .NET 4.0 . I have called the solution MvcDemo.

After clicking OK, I will choose Internet Application as the template and Razor as the view engine and also create unit test project.

Visual Studio creates a working application once the OK button is hit. Folders and files have been created by default for Controllers, Models, Views, Filters, Scripts, Contents, etc. The screen shot below shows the full structure.

The application can now be started in Debug mode by hitting F5.

The application, by default, shows some informative messages. It’s important to note that the data for this page is obtained from Index.cshtml View which is under the Home sub-folder of View folder. The View contains mostly static content and dynamically obtains some information referred ViewBag.Message and ViewBag.Title property as shown below.

The value of ViewBag.Title property is set in the first couple of lines within the View. The ViewBag.Message property is set within the Index() method of HomeController class which is located within the Controller directory.


        namespace MvcDemo.Controllers
        {
            public class HomeController : Controller
            {
                public ActionResult Index()
                {
                    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
         
                    return View();
                }
            }
        }