I have an older copy of the .net kendo ui sample code. In the sample, the following ViewModel is included.
public class ProductViewModel
{
public ProductDTO ProductMeta { get; set; }
public int ProductID { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public int UnitsInStock { get; set; }
public bool Discontinued { get; set; }
public DateTime LastSupply { get; set; }
public int UnitsOnOrder { get; set; }
}
The VM also uses this class.
public class ProductDTO
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public decimal? UnitPrice { get; set; }
}
In the Areas/razor/views/grid/editing.cshtml file, if I change the following line
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice).Width(140);
TO....
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.ProductMeta.UnitPrice).Width(140);
The binding works correctly on update. So if I change the value of unit price to 25, the vm.ProductMeta.UnitPrice value will be set appropriately to 25.
However, if I add the following statement (statement bolded), the binding no longer works
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.ProductID);
model.Field(p => p.ProductMeta.UnitPrice).DefaultValue(30);
})
Inspecting the payload sent to the GridController.EditingUpdate() method, I notice that the value for ProductMeta.UnitPrice is not changed.
Is there a work around for this?
It seems like the grid is not overly fond of working with nested objects exposed from VMs, especially when using the Model() method.
I'd rather not have to flatten my VM in order to get this to work.
Thanks!
public class ProductViewModel
{
public ProductDTO ProductMeta { get; set; }
public int ProductID { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public int UnitsInStock { get; set; }
public bool Discontinued { get; set; }
public DateTime LastSupply { get; set; }
public int UnitsOnOrder { get; set; }
}
The VM also uses this class.
public class ProductDTO
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public decimal? UnitPrice { get; set; }
}
In the Areas/razor/views/grid/editing.cshtml file, if I change the following line
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice).Width(140);
TO....
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.ProductMeta.UnitPrice).Width(140);
The binding works correctly on update. So if I change the value of unit price to 25, the vm.ProductMeta.UnitPrice value will be set appropriately to 25.
However, if I add the following statement (statement bolded), the binding no longer works
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.ProductID);
model.Field(p => p.ProductMeta.UnitPrice).DefaultValue(30);
})
Inspecting the payload sent to the GridController.EditingUpdate() method, I notice that the value for ProductMeta.UnitPrice is not changed.
Is there a work around for this?
It seems like the grid is not overly fond of working with nested objects exposed from VMs, especially when using the Model() method.
I'd rather not have to flatten my VM in order to get this to work.
Thanks!