This is a migrated thread and some comments may be shown as answers.

ClientDetailTemplateId and Id of Parent

7 Answers 326 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gusev
Top achievements
Rank 1
Gusev asked on 22 Apr 2013, 02:16 PM
Hello!
I have grid, which contains ClientDetailTemplateId("//here template with Grid -> " MyGridChild"...
If I create new object in MyGridChild, I want get Id him Parent 
Please help

7 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 24 Apr 2013, 06:34 AM
Hi Gusev,


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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 24 Apr 2013, 07:05 AM
Hello!!!!!
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}" })
If I edit , all are okay
0
Vladimir Iliev
Telerik team
answered on 30 Apr 2013, 11:39 AM
Hi Gusev,

 
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?

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 30 Apr 2013, 12:44 PM
I changed your project and bug appeared
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)
0
Accepted
Vladimir Iliev
Telerik team
answered on 30 Apr 2013, 01:50 PM
Hi Gusev,

 
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
    }));
}
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alex
Top achievements
Rank 1
answered on 20 Feb 2018, 02:19 PM

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

0
Stefan
Telerik team
answered on 22 Feb 2018, 07:03 AM
Hello, Alex,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Gusev
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Gusev
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or