I have an object (Object1), which contains a child object (Child). Thus, you would access the child by Object1.Child. In my ASP.NET MVC2 project, I a receiving the POST reply to the create method. The FormCollection contains properties for both the Object1 and Child objects. I cannot seem to get the child object to be updated with the "TryUpdateModel" function.
[HttpPost]
public ActionResult Create(FormCollection collection)
{
Object1 obj = new Object1();
obj.Child = new Child();
if (TryUpdateModel<Object1>(obj, "Object1", new[] { "ObjectName", "Child.ChildName" }))
{
// At this point, "ObjectName" is filled in, but "Child.ChildName" is not.
context.Object1s.AddObject(obj);
context.SaveChanges();
return RedirectToAction("Index");
}
return View(new Object1_ViewModel(obj));
}
Any help is appreciated.