Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Sat, 26-Jul-2014 Authors
All Time Authors
Sourav.Kayal
39750
Sheonarayan
37300
Niladri.Biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads

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

Questpond
Posted by under ASP.NET category on for Advance level | Points: 250 | Views : 238434 red flag
If you found plagiarised (copied) or inappropriate content,
please let us know the original source along with your correct email id (to communicate) for further action.
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
About the Author

Questpond

Full Name: Shivprasad Koirala
Member Level:
Member Status: PanelMember,Member,Microsoft_MVP,MVP,Administrator
Member Since: 9/3/2008 2:16:27 AM
Country: India
www.questpond.com
http://www.questpond.com

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers

Login to vote for this post.
Found interesting? Add this to:


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

Login to post response

Comment using Facebook(Author doesn't get notification)