29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

public class Address {<br />

public string Line1 { get; set; }<br />

public string Line2 { get; set; }<br />

public string City { get; set; }<br />

public string PostalCode { get; set; }<br />

public string Country { get; set; }<br />

}<br />

}<br />

public enum Role {<br />

Admin,<br />

User,<br />

Guest<br />

}<br />

The example project contains a simple Home controller that I use to display forms and receive form posts. You can see the<br />

definition of the HomeController class in Listing 22-2.<br />

Listing 22-2. The Contents of the HomeController.cs File<br />

using System.Web.Mvc;<br />

using HelperMethods.Models;<br />

namespace HelperMethods.Controllers {<br />

public class HomeController : Controller {<br />

public ActionResult Index() {<br />

};<br />

ViewBag.Fruits = new string[] { "Apple", "Orange", "Pear" };<br />

ViewBag.Cities = new string[] { "New York", "London", "Paris"<br />

string message = "This is an HTML element: ";<br />

}<br />

return View((object)message);<br />

}<br />

}<br />

public ActionResult CreatePerson() {<br />

return View(new Person());<br />

}<br />

[HttpPost]<br />

public ActionResult CreatePerson(Person person) {<br />

return View(person);<br />

}<br />

It is the two CreatePerson action methods that I will be using in this chapter, both of which render the<br />

/Views/Home/CreatePerson.cshtml view file. In Listing 22-3, you can see the CreatePerson view from<br />

the end of the last chapter, with a simple change.<br />

Listing 22-3. The Contents of the CreatePerson.cshtml File<br />

580

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!