So, I am looking for a transition from MVC 1.0 to RTM MVC 2.0 . One of the conventions I'd like to start is to use strongly typed HTML helpers to create controls such as text fields.
However, it does not appear to be an easy jump. I tried wrapping my first form, replacing the lines as follows:
<%= Html.TextBox("FirstName", Model.Data.FirstName, new {maxlength = 30}) %>
... for such lines:
<%= Html.TextBoxFor(x => x.Data.FirstName, new {maxlength = 30}) %>
Previously, this would map to the appropriate view model in POST using the following method signature:
[HttpPost]
public ActionResult Registration(AccountViewInfo viewInfo)
Instead, it is currently returning an empty object. I believe the disconnect is that we pass the view model to a larger population object that has some page metadata and other fun things with it (from here x.Data.FirstNameinstead x.FirstName).
So my question is: what is the best way to use strongly typed helpers, while still allowing the MVC framework to appropriately drop the collection of forms into my view model, as it does on the source line? Is there a way to do this without changing the aggregate type that we pass to the view?
Thank!
: , bind , , . , , , , , Data.