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

Invalid template when specifying ClientTemplateId for grid

3 Answers 266 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 14 Nov 2014, 10:11 PM
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.
























3 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 14 Nov 2014, 10:15 PM
I have attached the error that appears as well as the source of the page from the browser.
0
Peter
Top achievements
Rank 1
answered on 17 Nov 2014, 05:21 PM
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.
0
Phil
Top achievements
Rank 1
answered on 31 Jan 2017, 12:13 PM

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.

 

Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Phil
Top achievements
Rank 1
Share this question
or