I have not been using MVC3 for that long and think this is a flaw in my knowledge than a real issue.
I have an object that has a few basic properties and then a collection of inner objects, (simplified version):
public class myClass
{
public string Name { get; set; }
public string Location { get; set; }
public List<myOtherClass> Children { get; set; }
}
public class myOtherClass
{
public string Name { get; set; }
public int Age { get; set; }
}
I have a view that is strongly typed to the "myClass" object. I use the @html.editorfor for the name and location then a foreach for the children objects. in the foreach I again use editorfor's for each of their properties.
On postback(httppost action) the myClass name and location are filled out but the children list is empty.
I am not sure how I should craft the view to ensure it populates all the child elements.
I tried both:
[httppost]
public actionresult myaction(myClass myclass)
{
}
and:
[httppost]
public actionresult myaction()
{
myClass myclass = new myClass();
TryUpdateModel(myclass);
}