ASP.NET MVC 学习心得 (1) - 怎样创建简单程序

使用VS2008 创建ASP.NET MVC Web Application 项目。

This C# source file under Controllers folder

[HandleError]

public class HomeController : Controller

{

public ActionResult Index()

{

ViewData["Message"] = "Welcome to ASP.NET MVC!";

ViewData["Name"] = "John";

   

return View();

}

   

public ActionResult About()

{

return View();

}

}

   

This ASP.NET web page under Views folder

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

   

<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server">

<title>Home Page</title>

</asp:Content>

   

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">

<h2><%= Html.Encode(ViewData["Message"]) %></h2>

<h2><%= Html.Encode(ViewData["Name"]) %></h2>

<p>

To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.

</p>

</asp:Content>

posted @ 2009-04-09 11:41  许晓光  阅读(199)  评论(0编辑  收藏  举报