278Microsoft Visual Studio 2010: A Beginner’s Guide

<div class="editor-field">

<%= Html.TextBoxFor(model => model.Age) %> <%= Html.ValidationMessageFor(

model => model.Age) %>

</div>

<div class="editor-label">

<%= Html.LabelFor(model => model.Birthday) %> </div>

<div class="editor-field">

<%= Html.TextBoxFor(model => model.Birthday) %> <%= Html.ValidationMessageFor(

model => model.Birthday) %>

</div>

<div class="editor-label">

<%= Html.LabelFor(model => model.Income) %> </div>

<div class="editor-field">

<%= Html.TextBoxFor(model => model.Income) %> <%= Html.ValidationMessageFor(

model => model.Income) %>

</div>

<p>

<input type="submit" value="Create" />

</p>

</fieldset>

<% } %>

<div>

<%=Html.ActionLink("Back to List", "Index") %> </div>

</asp:Content>

The ValidationMessageFor Html helper displays any errors that occur on this page. The error messages are displayed whenever the Controller action method adds the error to the ModelState. When the user clicks the Submit button, this page will post back to the Create method with the AcceptVerbs attribute for post. Figure 9-8 shows the Create screen when running.

In addition to creating a new Customer, you can edit existing Customers, as is discussed next.

Page 301
Image 301
Microsoft 9GD00001 manual Microsoft Visual Studio 2010 a Beginner’s Guide