ClientDetailTemplateId and Id of Parent

8 posts, 1 answers
  1. Gusev
    Gusev avatar
    83 posts
    Member since:
    Dec 2012

    Posted 22 Apr 2013 Link to this post

    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

  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2200 posts

    Posted 24 Apr 2013 Link to this post

    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!
  3. Gusev
    Gusev avatar
    83 posts
    Member since:
    Dec 2012

    Posted 24 Apr 2013 Link to this post

    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
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2200 posts

    Posted 30 Apr 2013 Link to this post

    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!
  5. Gusev
    Gusev avatar
    83 posts
    Member since:
    Dec 2012

    Posted 30 Apr 2013 Link to this post

    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)
  6. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2200 posts

    Posted 30 Apr 2013 Link to this post

    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!
  7. Alex
    Alex avatar
    1 posts
    Member since:
    Nov 2017

    Posted 20 Feb 2018 Link to this post

    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

  8. Stefan
    Admin
    Stefan avatar
    2880 posts

    Posted 22 Feb 2018 Link to this post

    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.
Back to Top