Handling control name prefixing in grid of grandchild objects?

2 posts, 1 answers
  1. Kevin
    Kevin avatar
    12 posts
    Member since:
    Jan 2015

    Posted 16 Mar 2015 Link to this post

    I have an edit view which has a couple properties, plus an array of child objects.  The view uses a tabStrip for those child objects, one tab page per child.  Those child objects have a couple properties, and also an array of grandchild objects that are displayed in a grid.

    I'm using a partial view to display the child object properties and the grandchildren grid.

    The content of the tabStrip pages is defined by:

    .Content(Html.PartialFor(model => model.Children[i], "_TheChildPartialView").ToHtmlString());

    That provides the automatic prefixing of the child object's controls with "Children[(index)]", such as name="Children[0].SomeChildProperty", which is perfect.

    But this causes a problem on the grid for the grandchildren.  When I click in a cell to edit it, the input that is created is given name="Children[0].SomeGrandchildProperty".  The input textbox is not given the value that was already in the cell, and when I leave the edit cell after changing the value the error is raised "Uncaught TypeError: Cannot read property '0' of undefined" which is shown to be coming from this code (looks like it is in C.extend.set of kendo.all.min.js):

    (function(d
    /**/) {
    return d.Children[0].SomeGrandchildProperty
    })

    I'm naming the grid on the partial view with .Name("GrandchildrenForChild" + Model.Index), so that eliminates conflicts with the grid itself from having multiple grids on the page.  But I don't know how to do deal with the automatic prefix causing problems in the edit cells of the grid.  Anyone have ideas how to handle that?
  2. Answer
    Daniel
    Admin
    Daniel avatar
    2230 posts

    Posted 18 Mar 2015 Link to this post

    Hello Kevin,

    You could clear the prefix before rendering the grid and then restore it if needed e.g.
    @{
        var prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
        ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
    }
    @(Html.Kendo().Grid<MyModel>()
        ...
    )
    @{
        ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
    }


    Regards,
    Daniel
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top