1、GuestBook


GuestBook
Controller:
GuestBookController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Mvc1.Controllers
{
    public class GuestBookController : Controller
    {
        //
        // GET: /GuestBook/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Sign(string name, string email, string comments)
        {
            ViewData["name"] = name;
            ViewData["email"] = email;
            ViewData["comments"] = comments;
            return View("ThankYou");
        }
    }
}

View :
Index.aspx

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Guest Book</h2>
    <p>
        Please sign the Guest Book!</p>
    <form method="post" action="/GuestBook/Sign">
    <fieldset>
        <legend>Guest Book</legend>
        <%=Html.Label("Name") %>
        <%=Html.TextBox("Name") %>
        <%=Html.Label("Email") %>
        <%=Html.TextBox("Email")%>
        <%=Html.Label("Comments") %>
        <%=Html.TextArea("Comments", new {rows=6,cols=30 })%>
        <div>
         <input type="submit" value="Sign" />
        </div>
    </fieldset>
    </form>
</asp:Content>

View:
    ThankYou.aspx

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ThankYou
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        ThankYou</h2>
    <p>
        Thank you for signing the Guest Book! You entered:</p>
    Name:<%=ViewData["name"] %><br />
    Email:<%=ViewData["email"] %><br />
    Comments:<i><%=ViewData["comments"] %></i>
</asp:Content>

CSS:
  Site.cssは次のコードを追加します.


fieldset label
{
 display:block;    
}

fieldset input
{
    display:block;
    margin-bottom:5px;
}

http://localhost:2067/GuestBook/Index
2011-5-16 11:08 danny