I modified this example to show one of the behaviors I am seeing with child objects.
http://www.telerik.com/community/code-library/aspnet-mvc/grid/batch-editing-with-combobox-editor-template.aspx
A child object for this example is a property that is an object where I want to bind to one or more of it's properties. The child object I added is Customer as a NewCustomer property.
namespace BatchEditingWithComboBoxEditorTemplate.Models { public class EditableOrder { public int OrderID { get; set; } [UIHint("Employee"), Required] public EditableEmployee Employee { get; set; } [DataType(DataType.Date), Required] public DateTime OrderDate { get; set; } [DataType(DataType.Currency), Required] public decimal Freight { get; set; } public Customer NewCustomer { get; set; } } public class Customer { public string Name { get; set; } public string Address { get; set; } } }
The controller is changed like this:
HomeController.cs: [GridAction] public ActionResult _SelectBatchEditing() { using (var nw = new NWDataContext()) { List<EditableOrder> list = nw.Orders .Select(o => new EditableOrder { OrderID = o.OrderID, OrderDate = o.OrderDate ?? DateTime.Now, Employee = new EditableEmployee { EmployeeID = o.Employee.EmployeeID, FirstName = o.Employee.FirstName, LastName = o.Employee.LastName }, NewCustomer = new Customer() { Name = "<new>", Address = "<unknown>" }, Freight = o.Freight ?? 0 }) .ToList(); return View(new GridModel(list)); } } The view changed like this:
Index.cshtml: .Columns(columns => { columns.Bound(o => o.OrderID).Width(100); columns.Bound(o => o.Employee).ClientTemplate("<#= (Employee==null)? '' : (Employee.FirstName + \" \" + Employee.LastName) #>").Width(230); columns.Bound(o => o.OrderDate).Width(150); columns.Bound(o => o.Freight).Width(220); columns.Bound(o => o.NewCustomer.Name).Width(100); columns.Bound(o => o.NewCustomer.Address).Width(100); columns.Command(commands => commands.Edit()).Title("Edit").Width(200); }) You can see on the screen shots the fields are displaying correctly, but when being saved it skips a one of the child properties.
It also will erase values randomly if you have keyboard naviation on and have a child object is bound in this manner.
This issue has come up because the requirement to flatten out every object to a view model makes binding tedious at best. In a small domain it might not be a problem, but in a domain with hundreds of classes and thousands of properties, this will double our maintainance and slow down development.
Please let me know if there is a solution.