Create a project of MVC from your Visual Studio 2008:
After selecting ASP.Net MVC Web Application change the name to “HelloWorld” and press OK.
Don’t select yes for Test Project as we don’t need testing for this simple example here is the screen shot of project created by wizard for us which have three main folders:
1- Controllers – All the logic to control the flow of pages.
2- Model: All business logics.
3- Views: All front end designs

If you run this project you can see the default page like this:

Our goal for this blog is to change the highlighted text which is “Welcome to Asp.Net MVC!” to “Welcome to Hello World!”
Now look into the folders you will find HomeController class in Controller folder where you can see a Action Index() this is responsible to set the text for the ViewData[“Message”] and return it to View.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace HelloWorld.Controllers
{
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to Hello World!";
return View();
}
public ActionResult About()
{
return View();
}
}
}
Now the question is how this message is set at View. Have a look in Views Folder and then Home Folder there is Index.aspx file which is a view for Home and About.aspx file is for About View which works when you click on the respective tabs:

Here is the code for Index.aspx:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %>h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvca>.
p>
asp:Content>
Here the text sets up <h2><%= Html.Encode(ViewData["Message"]) %>h2>
Now go back to HomeController and change the text in Index Action to:
From:
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
To:
public ActionResult Index()
{
ViewData["Message"] = "Welcome to Hello World!";
return View();
}
And run the project now:
Download the code here.


