How to create a simple hello world ASP.NET MVC? (Tutorial No: 1)

Questpond
Posted by in ASP.NET category on for Advance level | Points: 250 | Views : 323741 red flag
Rating: 5 out of 5  
 1 vote(s)

In this tutorial we will see how to create a first MVC application using VS 2010 and the MVC 2 template. This complete series is divided in to 50 parts with labs and video demos.

How to create a simple hello world ASP.NET MVC? (Tutorial No: 1)

Contents

Introduction

Goal: - Create a simple ASPX page with Hello world controller.

         Video demonstration
               Step1:- Create project
               Step 2:- Add controller
               Step 3:- Add View
               Step 4:- Run the application

So what’s in the next tutorial?   
                          

Introduction

In this tutorial we will see how to create a first MVC application using VS 2010 and the MVC 2 template. This complete series is divided in to 50 parts with labs and video demos. We hope this complete series will help you to understand MVC step by step in a structured manner.

Click here for the Part 2 of ASP.NET MVC article.

Click here for the Part 3 of ASP.NET MVC article.

Click here for the Part 4 of the ASP.NET MVC article.

Click here for the Part 5 of the ASP.NET MVC article.

Click here for the Part 6 of the ASP.NET MVC article.

Click here for the Part 7 of the ASP.NET MVC article.

Click here for the Part 8 of the ASP.NET MVC article.

Click here for the Part 9 of the ASP.NET MVC article.

Get more videos on .NET/ASP.NET interview questions and answers

Pre-requisite for MVC

• Visual Studio 2010 or the free Visual Web Developer 2010 Express. These include ASP.NET MVC 2 template by default.
• Visual Studio 2008 SP1 (any edition) or the free Visual Web Developer 2008 Express with SP1. These do not include ASP.NET MVC 2 by default; you must also download and install ASP.NET MVC 2 from http://www.asp.net/mvc/  .


Goal: - Create a simple ASPX page with Hello world controller.

In this lab we will create a simple hello world program using MVC template. So we will create a simple controller, attach the controller to simple index.aspx page and view the display on the browser.

Video demonstration

In case you are fed up to read the complete article watch the below 5 minutes video to understand the same.

Step1:- Create project

Create a new project by selecting the MVC 2 empty web application template as shown in the below figure.



Once you click ok, you have a readymade structure with appropriate folders where you can add controllers, models and views.

Step 2:- Add controller

So let’s go and add a new controller as shown in the below figure.


 

Once you add the new controller you should see some kind of code snippet as shown in the below snippet.

public class Default1Controller : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
}

Step 3:- Add View


Now that we have the controller we need to go and add the view. So click on the Index function which is present in the control and click on add view menu as shown in the below figure.
 



The add view pops up a modal box to enter view name which will be invoked when this controller is called as shown in the figure below. For now keep the view name same as the controller name and also uncheck the master page check box.

Once you click on the ok button of the view, you should see a simple ASPX page with the below HTML code snippet. In the below HTML code snippet I have added “This is my first MVC application”.


Step 4:- Run the application


If you do a CNTRL + F5 you should see an error as shown in the below figure. This error is obvious because we have not invoked the appropriate controller / action.
 

If you append the proper controller on the URL you should be able to see the proper view.


 

So have a toast of beer for your first ASP.NET MVC application.
 

So what’s in the next tutorial?

Now that we have created a simple MVC hello world, it’s time to see how we can pass data from controllers to views. The first hit comes to the controller which will load your business objects or model and you would like to transfer these objects to the view to display them. Click here to view the 2nd part of ASP.NET MVC in article.

 

Page copy protected against web site content infringement by Copyscape

Login to vote for this post.

Comments or Responses

Posted by: Laghaterohan on: 4/12/2011 | Points: 25
Indeed nice one..when shall i expect part 2 and so on??
Posted by: Susanthampy on: 6/13/2011 | Points: 25
nice
Posted by: Sanepete on: 9/19/2011 | Points: 25
The pictures have disappeared!

Shocking!
Posted by: Irshadvaza on: 12/30/2011 | Points: 25
Very good post.It is very useful to understand mvc.Expect with Jquery in part 2.


Posted by: Akiii on: 1/16/2012 | Points: 25
great starting Sir !

Thanks and Regards
Akiii
Posted by: Maksim20032 on: 1/17/2014 | Points: 25
How to develop basic Asp.Mvc website, retrieving data from database and print it in View


http://www.docstorus.com/viewer.aspx?code=64a851b3-0b51-436b-ac02-9ae9f7ea04af
Posted by: Channus on: 9/26/2015 | Points: 25
A step by step guide for MVC daily a new tutorial about MVC. Please Visit
http://sourceofcsharp.com/forumdisplay.php?fid=14

Login to post response

Comment using Facebook(Author doesn't get notification)