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

Accessing properties of scoped object

3 Answers 295 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 11 Nov 2014, 04:44 AM
I have a grid that I'm assigning as a child template to a parent grid.  The child template looks like this:

<script id="client-template" type="text/x-kendo-template">
    @(Html.Kendo().Grid<EnrolledUnit>()
        .Name("grid_#=Enrolment.EnrolmentId#")
        .Columns(columns =>
        {
            columns.Bound(enrolledUnit => enrolledUnit.DisplayName);
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read
                .Action("EnrolledUnits_Read", "EnrolledUnits", new { enrolmentId = "1" })
            )
        )
        .ToClientTemplate()
    )
</script>

In particular, this line is what I need help with: Name("grid_#=Enrolment.EnrolmentId#")

That line doesn't work - the parser fails (returns a Javascript error saying "Invalid template").  It seems to be the use of dot syntax within that Name method that's causing the issue.  If I change my template to this:

<script id="client-template" type="text/x-kendo-template">
    #=Enrolment.EnrolmentId#
</script>

The EnrolmentId is output with no issues, proving that the item exists and the property exists and is populated. It seems to be using the dot syntax in the Name method specifically that is causing the problem.

3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 12 Nov 2014, 04:44 PM
Hi Nick,

I am afraid that nested properties within a grid name with MVC are not supported. Do you really need to set the grid name according to the supplied data, do you reference the grids on a later stage and perform some operations? As a workaround I can suggest you to use the detailInit event and initialize the grid using JavaScript as in this demo:

http://demos.telerik.com/kendo-ui/grid/hierarchy

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nick
Top achievements
Rank 1
answered on 12 Nov 2014, 09:35 PM
Hi Kiril,

No problem, I suspected that may have been the case.  I ended up flattening my ViewModel so I didn't need to use a nested property.  Cheers!


- Nick
0
Kiril Nikolov
Telerik team
answered on 13 Nov 2014, 12:04 PM
Hi Nick,

Flattening the ViewModel is another good option that I forgot to mention!

Glad you have it working!

In case you have any further questions, please do not hesitate to contact us.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Templates
Asked by
Nick
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Nick
Top achievements
Rank 1
Share this question
or