DinnerFormViewModel

Aug 31, 2010 at 3:38 AM
Edited Aug 31, 2010 at 3:39 AM

In the book "Professional ASP.NET MVC 2" page 89:

We can then update our View code to work off of it. Notice in the following code how we are not
changing the names of the input elements we are creating (the form elements will still be named
“Title”, “Country”) — but we are updating the HTML Helper methods to retrieve the values
using the DinnerFormViewModel class:

 

<p>
<%: Html.LabelFor(m => m.Title) %>
<%: Html.TextBoxFor(m => m.Title) %>
<%: Html.ValidationMessageFor(m => m.Title, "*") %>
</p>
<p>
<%: Html.LabelFor(m => m.Country) %>
<%: Html.DropDownListFor(m => m.Country, Model.Countries) %>
<%: Html.ValidationMessageFor(m => m.Country, "*") %>
</p>

 

Why we can still use m => m.Title, m => m.Country?  After changing Inherits=”System.Web.Mvc.ViewPage<NerdDinner.Controllers.Dinner> to Inherits=”System.Web.Mvc.ViewPage<NerdDinner.Controllers.DinnerFormViewModel> I think m is an object of DinnerFormViewModel, and we should change the above code to something like this:

<p>
<%: Html.LabelFor(m => m.Dinner.Title) %>
<%: Html.TextBoxFor(m => m.Dinner.Title) %>
<%: Html.ValidationMessageFor(m => m.Dinner.Title, "*") %>
</p>
<p>
<%: Html.LabelFor(m => m.Dinner.Country) %>
<%: Html.DropDownListFor(m => m.Dinner.Country, Model.Countries) %>
<%: Html.ValidationMessageFor(m => m.Dinner.Country, "*") %>
</p>