In this post I will explain
how to print Hello message in MVC2.0 in .NET.
First create a new Asp.net MVC2.0 project in visual studio
2010.
Select the visual
studio c#/web Template group on left , then choose the “ASP.NET MVC 2 Empty Web
Application” , name the project and click ok button.
Go to solution explorer
-> right click on controller folder -> select add
-> click on Controller ->
give a controller name i.e HomeController -> click Add button . This will
create HomeController.aspx.cs page with the following code like this.
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
namespace
MvcHello.Controllers
{
public
class HomeController
: Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
Let change the following two thing in the
above code
·
Change the method to return a string instead of
ActionResult
·
Change the return statement to return “Hello
From Home”.
After changing the two thing the code will look like this:
public string Index()
{
return "Hello From
Home";
}
Now it’s time to run the code. So press F5.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.