ASP.NET MVC 學習心得 (1) - 怎樣建立簡單程式

林堯彬發表於2020-04-04

使用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>

轉載於:https://www.cnblogs.com/xuxiaoguang/archive/2009/04/09/1432321.html

相關文章