7 Answers, 1 is accepted
I would suggest to send the master record ID as additional parameter to the Update action in the following way:
<script id=
"template"
type=
"text/kendo-tmpl"
>
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
.Name(
"grid_#=EmployeeID#"
)
//Child grid - send parent record model ID (in current case EmployeeID) with each update / create request
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action(
"HierarchyBinding_Orders"
,
"Grid"
,
new
{ employeeID =
"#=EmployeeID#"
}))
.Update(update => update.Action(
"HierarchyUpdate_Orders"
,
"Grid"
,
new
{ employeeID =
"#=EmployeeID#"
}))
Kind Regards,
Vladimir Iliev
the Telerik team
If I create my object in MyChildGrid(or in "grid_#=EmployeeID#") I dosn't have Id (I attached my console.png, where IdParent = 0) and I need get him
I use this:
.Update("Edit", "Complectation", new { IdParent = "${Id}" })
.Create("Create", "Complectation", new { IdParent = "${Id}" })
Please find attached the example of Grid hierarchy editing - could you please check it and let me know how it differs from your real setup?
Vladimir Iliev
the Telerik team
please, see project, which I attached
Maybe this error there, because I have 3 Id (Parent = Id, ChildParent = Id, ChildChildParent = Id)
(2 mb ... so sad :( ... I deleted all packages and all scripts)
After reviewing the provided project it seems that the issue is coming from sending the parent record ID in the "id" variable which is reserved for the child grid newly created model. I would suggest to send the parent record ID in variable prefixed with parent record model name - please check the example below:
Order Grid dataSource:
.Read(read => read.Action(
"Read_Orders"
,
"Orders"
,
new
{ employeesId =
"#=Id#"
}))
.Update(update => update.Action(
"Update_Order"
,
"Orders"
))
.Create(create => create.Action(
"Create_Order"
,
"Orders"
,
new
{ employeesId =
"#=Id#"
}))
.Destroy(destroy => destroy.Action(
"Destroy_Order"
,
"Orders"
)))
Read_Orders action:
public
ActionResult Read_Orders([DataSourceRequest] DataSourceRequest request,
int
employeesId)
{
return
Json(context.Orders.Where(o => o.EmployeeID == employeesId).ToDataSourceResult(request, o =>
new
OrderViewModel()
{
Id = o.OrderID,
ShipAddress = o.ShipAddress,
ShipCountry = o.ShipCountry,
ShipName = o.ShipName,
ShippedDate = o.ShippedDate
}));
}
Vladimir Iliev
the Telerik team
Hi,
I
know that this post is somewhat outdated now, but I have been trying to do
something similar with .Net Core 2.0. I had been struggling with getting the
parent id to return to the controller from my nested grid. I found the solution
and have documented it below.
I attempted to do what Vladimir had suggested by creating a new property with the same name as my read action, but this resulted in 0 being posted to the controller method.
.Read(read => read.Action(
"GetLo"
,
"FrameworkConfig"
,
new
{ parentId =
"#=Id#"
}))
.Create(update => update.Action(
"Lo_Create"
,
"FrameworkConfig"
,
new
{ parentId =
"#=Id#"
}))
Changing the property in the create action from parentId to pid = “#=id” resulted in the correct parent id being posted to the controller. In my case both the read and create actions could not use the same property name.
.Read(read => read.Action(
"GetLo"
,
"FrameworkConfig"
,
new
{ parentId =
"#=Id#"
}))
.Create(update => update.Action(
"Lo_Create"
,
"FrameworkConfig"
,
new
{ pId =
"#=Id#"
}))
Kind Regards,
Alex P
Thank you for sharing the solution with the community it is highly appreciated.
The difference may occur as since 2013 many changes were made to the Grid and this could result in different behavior.
Additionally, I updated your Telerik points for sharing this with the community.
Regards,
Stefan
Progress Telerik