Click here to Skip to main content
Licence CPOL
First Posted 16 Dec 2009
Views 69,201
Bookmarked 44 times

ASP.NET MVC Quick Start Tutorial - Create a Small ASP.NET MVC application step by step

By Techaxe | 4 Jan 2010
This article will help you create a small ASP.NET MVC application step by step.
6 votes, 28.6%
1
1 vote, 4.8%
2
7 votes, 33.3%
3
4 votes, 19.0%
4
3 votes, 14.3%
5
3.07/5 - 21 votes
μ 3.00, σa 2.44 [?]

Introduction

This tutorial will help you create a small ASP.NET MVC sample step by step. 

Using the Code

In this tutorial, we will be creating our own Model, View and Controller and make them all work together. For this tutorial, create a new ASP.NET MVC application using Visual Studio. The motive of this tutorial is to print our information on the webpage using MVC philosophy.

Let's briefly understand what we intend to do and then we shall perform these steps one by one to create our web page. For our motive, we need a model to hold the information. The model would be a class with the required properties. Then we will create a View to display the information in a tabular format. Finally we will need a Controller to receive our request from the webpage and return the response to us. Let’s get started with our task.

Creating the Model

On the Models folder, right click and create a new class by clicking on Add -> Class. See figure below:

Name the class as PersonalInformation.cs. Create the following properties in the Model:

These properties have been created using C# 3.0 specifications and they do not need private fields to be created for them. This completes our model. Let’s now create our View which we shall use to display the information in the browser.

Creating the View

On the views folder, right click and create a new folder. Name the folder as PersonalInformation. Right click on the PersonalInformation folder and select Add -> View . See the figure below:

Name the View as Index and check the box which says “Create a strongly-typed view” and select the class that will act as a Model for this View. You might not see any class in the View data class drop down. Compile the application once and then add a View. You will see the PersonalInformation class in the dropdown list. Select a master page for your View. Once these steps are finished, click Add and the View gets created. Refer to the figure below.

Creating our Controller

Now that we are done with creating the Model and the View, let's create our Controller. Right click on the Controllers folder and select Add -> Controller.

Name the Controller as PersonalInformation. Please make sure that the name of the Controller and the name of the folder that we created under the Views folder are the same.

You will see that by default a method by the name Index is created in the Controller class. This method has ActionResult as a return type and it returns a View. We will dig into the details of the return type and other details in the next tutorials. Let’s now do some coding and pass the Model to the View so that it can display the information on the webpage. Type in the following code into your Controller class:

controller.jpg

This code creates a Model and fills data into it. We then pass on that model to the view. Now the last piece that is left is to display the information using the View. For this, open up the View that we created and type in the following code in it:

That’s it. We have finished with our Model, View and Controller. Now let’s compile and run our application. Below is the final output that you will see in the browser. Please carefully look at the URL in the address bar of the browser.

finaloutput.jpg

With this, we finish this tutorial. For a few more ASP.NET MVC tutorials, please visit my blog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Techaxe

Founder
Mind Field Software Solutions Pvt Ltd
India India

Member

Follow on Twitter Follow on Twitter
We are a team of experts with industry experience in providing software solutions over a wide range of spectrum. Over the period of time we have practiced and refined our software designing, development and deployment skills. With our strong and exceptionally talented team in US we stand a strong chance to make a mark in the software industry over the coming years.
 
Bootcamp is a leap forward in cultivating young engineering minds and making them industry ready. In the process of doing so we will continuously be in the process of strengthening our team @Mind Field Software Solutions Pvt Ltd by pouring in the trained talent from Bootcamp. All trainers at Bootcamp are working professionals with vast software experience. Each of our faculty member is equipped with working experience rather than just teaching experience. Please visit our company website at http://www.bootcampedu.com . We mainly provide .net training and our current office address is SCF - 83, Model Town Phase 1, Bathinda, Punjab.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberleopard44719:55 19 Dec '11  
GeneralMy vote of 3 PinmemberAmir Mahfoozi21:10 18 Dec '11  
QuestionERROR Pinmembersumitp174:34 15 Dec '11  
GeneralMy vote of 1 PinmemberPrince Antony G19:14 30 Nov '11  
Suggestion[My vote of 1] Not enough basic information Pinmemberlevteck10:28 30 Nov '11  
Suggestion[My vote of 2] The pictures/diagrams are not coming PinmemberMr.Sourav.Maitra21:27 24 Oct '11  
GeneralMy vote of 1 PinmemberManuel_Perez_II5:33 28 Sep '11  
GeneralMy vote of 1 Pinmemberkami52:40 26 Jul '11  
GeneralMy vote of 3 PinmemberVano Maisuradze1:13 8 Jun '11  
GeneralVery Poor PinmemberTarun Dudhatra5:06 14 Mar '11  
GeneralMy vote of 1 PinmemberTarun Dudhatra4:58 14 Mar '11  
GeneralImage is not coming in Chrome [modified] PinmemberAnjum.Rizwi20:56 2 Feb '11  
Generalproblem loading pics PinmemberPie At The Raven2:29 23 Jan '11  
GeneralCouldn't make head or tails out of this article Pinmemberioranet10:19 18 Jan '11  
GeneralMy vote of 5 Pinmemberamaresh54821:40 11 Aug '10  
GeneralMy vote of 4 PinmemberMember 40547741:24 7 Jul '10  
GeneralNice Article PinmemberPraneeth Babu K19:29 6 Mar '10  
GeneralThanks PinmembermathB5:59 27 Dec '09  
GeneralRe: Thanks Pinmemberbootcamp6:25 27 Dec '09  
GeneralGood One PinmemberAATVV20:37 22 Dec '09  
GeneralMy vote of 1 Pinmemberpanjkov23:31 19 Dec '09  
GeneralOK but... PinmemberSmirkinGherkin0:42 17 Dec '09  
GeneralRe: OK but... Pinmemberbootcamp0:54 17 Dec '09  
GeneralThanks PinmemberJigneshSE22:59 16 Dec '09  
GeneralRe: Thanks Pinmemberbootcamp0:00 17 Dec '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120209.1 | Last Updated 4 Jan 2010
Article Copyright 2009 by Techaxe
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid