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

Handling control name prefixing in grid of grandchild objects?

1 Answer 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 16 Mar 2015, 03:57 PM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 18 Mar 2015, 11:37 AM
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.

 
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or