Invalid template when specifying ClientTemplateId for grid

4 posts, 0 answers
  1. Peter
    Peter avatar
    14 posts
    Member since:
    Dec 2013

    Posted 14 Nov 2014 Link to this post

    I am trying to replicate the functionality of the hierarchy grid as shown in the demos. This is the code I have in my views:

    @(Html.Kendo().Grid<CrewListing>()
    .Name("grid")
    .Columns(columns =>
    {
    columns.Bound(x => x.Truck);
    columns.Bound(x => x.Name);
    columns.Bound(x => x.ActiveOrder);
    columns.Bound(x => x.ServicePoint).Filterable(false);
    columns.Bound(x => x.Region).Filterable(false);
    })
    .DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("RefreshTable", "Crew"))
    .Sort(sort => sort.Add(x => x.Truck).Descending())
    )
    .ClientDetailTemplateId("crewOrderTemplate")
    .Filterable()
    .Pageable()
    .Sortable()
    )

    <script id="crewOrderTemplate" type="text/kendo-template">
    @(Html.Kendo().Grid<CrewOrderListing>()
    .Name("grid_#=Truck#")
    .DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("GetCrewOrders", "Crew"))
    .Sort(sort => sort.Add(x => x.Customers).Descending())
    )
    .Columns(columns =>
    {
    columns.Bound(o => o.Order);
    columns.Bound(o => o.Device);
    columns.Bound(o => o.Customers);
    columns.Bound(o => o.OrderType);
    })
    .Pageable()
    .Filterable()
    .Sortable()
    .ToClientTemplate())
    </script>
    What ends up happening is I get the error "Invalid Template" in my browser console. If I make the detail template standalone by placing it outside the <script> block and removing the ToClientTemplate() function, it renders properly. My application does NOT have the AntiXssEncoder loaded.
























  2. Peter
    Peter avatar
    14 posts
    Member since:
    Dec 2013

    Posted 14 Nov 2014 in reply to Peter Link to this post

    I have attached the error that appears as well as the source of the page from the browser.
  3. Peter
    Peter avatar
    14 posts
    Member since:
    Dec 2013

    Posted 17 Nov 2014 Link to this post

    So after filling several buckets with tears and despair, it turns out that the viewmodel that my template grid is bound to has a display name attribute set for the Order property:

    [Display(Name = "Order #")]
    public string Order { get; set; }

    Notice how it has a "#" symbol in the name. If I get rid of the hash symbol:

    [Display(Name = "Order No")]
    public string Order { get; set; }

    Everything works fine. Would be nice if Kendo auto escaped symbols like this internally.
  4. Phil
    Phil avatar
    13 posts
    Member since:
    Mar 2014

    Posted 31 Jan 2017 Link to this post

    Something easy to check as well: ensure that the client detail template has this method specified:

    .ToClientTemplate()

    Otherwise you'll get the invalid template error. It would certainly be helpful if Telerik provided better, specific error messages indicating the source of such problems.

     

Back to Top