i see that asp.net mvc 2 has strongly typed helped and looking initially at the way it works i think maybe i am doing something wrong in asp.net mvc 1 in terms of data binding to render the view and post back to the controller.
I often have different objects for rendering the view and posting back to the controller. is this wrong ?? It seems natural as when rendering the view you often have a viewmodel that has lists for dropdowns, etc. but for your posting you only want the properties that are needed to post back.
for example, on the way in for rendering, my viewmodel might look like this
public class PersonViewModel
{
public int Age;
public string FIrst;
public JobCategory[] JobCategories;
public Sport[] Sports;
public int NumberOfChildren;
}
in this case, jobCategories and Sports is going to be used to populate a dropdown box. NumberOfchildren is going to just be html put in and i dont want it editable. When i want to post i only want to pass back a slim object with just the posted properties so i have another object
public class PersonUpdater
{
public int Age;
public string FIrst;
public int JobCategoryId;
}
these are the only properties that i need to pass back so my controller will look like this:
public ActionResult Update(PersonUpdater personUpdater)
{
_repository.UpdateModel(personUpdater).
}
so, given the above, assuming the strongly typed helper methods (below) seem useful for the way in but then may cause issues on posting back to the server if you are referrring to different properties.
http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx
any thoughts?