I have not used MVC3 for so long, and I think this is a flaw that I know than the real problem.
I have an object that has several basic properties, and then a set of internal 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 for myClass object. I use @ html.editorfor for name and location, and then for foreach for children. in foreach, I again use editorfor for each of my properties.
In the postback (httppost action), the name and location of myClass are populated, but the list of children is empty.
I'm not sure how I should handle the view so that it fills all the children.
I tried both:
[httppost]
public actionresult myaction(myClass myclass)
{
}
and
[httppost]
public actionresult myaction()
{
myClass myclass = new myClass();
TryUpdateModel(myclass);
}
source
share