Skip to content

Commit

Permalink
Listing 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
ngbrown committed Sep 14, 2010
1 parent 44e643d commit c828bc6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
27 changes: 20 additions & 7 deletions MvcApplication1/MvcApplication1/Controllers/GuestBookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,41 @@

namespace MvcApplication1.Controllers
{
using Models;

public class GuestBookController : Controller
{
//
// GET: /GuestBook/

public ActionResult Index()
{
return View();
var model = new GuestBookEntry();
return View(model);
}

//
// URL: /GuestBook/Sign
// POST: /GuestBook/

public ActionResult Sign(string name, string email, string comments)
[HttpPost]
public ActionResult Index(GuestBookEntry entry)
{
TempData["entry"] = entry;
return RedirectToAction("ThankYou");
}

public ActionResult ThankYou()
{
// do something with the values, such as send an email

ViewData["name"] = name;
ViewData["email"] = email;
ViewData["comments"] = comments;
if (TempData["entry"] == null)
{
return RedirectToAction("index");
}

var model = (GuestBookEntry)TempData["entry"];

return this.View("ThankYou");
return this.View(model);
}
}
}
9 changes: 9 additions & 0 deletions MvcApplication1/MvcApplication1/Models/GuestBookModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MvcApplication1.Models
{
public class GuestBookEntry
{
public string Name { get; set; }
public string Email { get; set; }
public string Comments { get; set; }
}
}
1 change: 1 addition & 0 deletions MvcApplication1/MvcApplication1/MvcApplication1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\AccountModels.cs" />
<Compile Include="Models\GuestBookModels.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
20 changes: 10 additions & 10 deletions MvcApplication1/MvcApplication1/Views/GuestBook/Index.aspx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.GuestBookEntry>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
Expand All @@ -10,23 +10,23 @@

<p>Please sign the Guest Book!</p>

<form action="/GuestBook/Sign" method="post">
<% using (Html.BeginForm()) { %>
<fieldset>
<legend>Guest Book</legend>

<%= Html.Label("Name") %>
<%= Html.TextBox("Name") %>
<%= Html.LabelFor(model => model.Name) %>
<%= Html.TextBoxFor(model => model.Name) %>

<%= Html.Label("Email") %>
<%= Html.TextBox("Email") %>
<%= Html.LabelFor(model => model.Email) %>
<%= Html.TextBoxFor(model => model.Email) %>

<%= Html.Label("Comments") %>
<%= Html.TextArea("Comments", new { rows=6, cols=30 }) %>
<%= Html.LabelFor(model => model.Comments) %>
<%= Html.TextAreaFor(model => model.Comments, new { rows=6, cols=30 }) %>

<div>
<input type="submit" value="Sign" />
<input type="submit" value="Create" />
</div>
</fieldset>
</form>
<% } %>

</asp:Content>
9 changes: 4 additions & 5 deletions MvcApplication1/MvcApplication1/Views/GuestBook/ThankYou.aspx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.GuestBookEntry>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
ThankYou
Expand All @@ -8,9 +8,8 @@

<h2>Thank You!</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>
Thank you for signing our Guest Book. You entered: <br />

<%= Html.DisplayForModel() %>

</asp:Content>

0 comments on commit c828bc6

Please sign in to comment.