Creating a Sample App in ASP.Net MVC

This article is all about developing your first sample or you can say simple application using ASP.NET MVC. This article includes all the major components required for the development procedure, like software, environment and how to install.

Getting Started

The best way to learn about how MVC works is to get started with building an application, so let's try that folks. First of all I'll take you through the software requirements, here we go.

Software Requirements

MVC runs on the following Windows Client Operating Systems:

  • Windows XP
  • Windows Vista
  • Windows 7
  • Windows 8

It runs on the following Windows Server Operating Systems:

  • Windows Server 2003
  • Windows Server 2008
  • Windows Server 2008 R2

MVC development tooling is included with Visual Studio, but the versions and the functionalities can vary with versions of Visual Studio.

Installing ASP.NET MVC

After ensuring the basic software requirements, it's time to install ASP.NET MVC on your development and platform machines.

If you have a previous version of MVC then you don't need to reinstall the entire setup again, what you need to do is just update it and you will get the latest version of MVC. For example if you have already used MVC 1, 2, 3 or 4 and you need to work upon MVC 5 then in this case, simply update the existing version.

Creating an ASP.NET MVC Application

After installing MVC, you'll have some options in your Visual Studio (Whatever versions you are using.)

Use the following procedure to create a MVC project.

Step 1

Begin with choosing a New Project, as shown in the figure below:

New Project

Select "Project...":

Select project

Step 2

Select Visual C# from the templates.

templates

Step 3

In the installed templates of Visual C# select Web template list. This displays a list of web application types in the center portion of the window.
 
center portion of the window

Step 4
 
You will get a Unit Test Project option on clicking OK, but this is not mandatory. You can select either Yes or you can go with No.
 
OK

Step 5

On again selecting OK, you will get a window like this. This window contains the basic code structure of the MVC development environment.
(You can reconfigure it depending on you and your requirements.)
 
MVC development environment

Coding
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace MvcApplication2.Controllers  
  8. {  
  9.     [HandleError]  
  10.     public class HomeController : Controller  
  11.     {  
  12.         public ActionResult Index()  
  13.         {  
  14.             ViewData["Message"] = "Welcome to ASP.NET MVC!";  
  15.   
  16.             return View();  
  17.         }  
  18.   
  19.         public ActionResult About()  
  20.         {  
  21.             return View();  
  22.         }  
  23.     }  

You can add your functionalities between this code depending on your requirements.


Similar Articles