I have a kendo grid and in the create action, I want to post back the content of another grid's data source to a razor pages server.
@(Html.Kendo().Grid<EntityModel>() .Name("mainGrid") .DataSource(ds => ds.Ajax() .Read(r => r.Url("/Index?handler=ReadEntity")) .Create(c => c.Url("/Index?handler=CreateEntity").Data("getData")) .Model(m => m.Id(id => id.EntityID)) ) ) function getData() { var otherModels = $("#otherGrid").data("kendoGrid").dataSource.data(); var temp = $.extend(true, {}, kendo.antiForgeryTokens(), { otherModels: otherModels }); return temp; }
The result looks like this
temp
- otherModels
- 0
- Name: xyz ...
- 0
The action:
public JsonResult OnPostCreateEntity(List<OtherViewModel> otherModels, [DataSourceRequest] DataSourceRequest request, EntityViewModel entityModel) //otherModels is empty
This works fine for collections of simple objects like integers, but in this case, an exception is thrown:
"Cannot read property 'field' of undefined"