Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 9: Creating Web Applications with ASP.NET MVC 277
The Add View screen in Figure 9-7 specifies strong typing on the Customer class, but
this time it selects Create as the View Content. Listing 9-10 shows the resulting View.
Listing 9-10 View for creating a new Customer
<%@ Page Title="" Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyShopCS.Customer>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent"
runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent"
runat="server">
<h2>Create</h2>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.CustomerID) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.CustomerID) %>
<%= Html.ValidationMessageFor(
model => model.CustomerID) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Name) %>
<%= Html.ValidationMessageFor(
model => model.Name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Age) %>
</div>