Accessing properties of scoped object

4 posts, 0 answers
  1. Nick
    Nick avatar
    2 posts
    Member since:
    Oct 2013

    Posted 10 Nov 2014 Link to this post

    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.
  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 12 Nov 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Nick
    Nick avatar
    2 posts
    Member since:
    Oct 2013

    Posted 12 Nov 2014 in reply to Kiril Nikolov Link to this post

    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
  5. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 13 Nov 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready