您的位置:首页 > 编程语言 > ASP

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

2009-04-09 11:41 453 查看
使用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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: