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

Template compile error - invalid template

5 Answers 199 Views
This is a migrated thread and some comments may be shown as answers.
Dimitrij
Top achievements
Rank 1
Dimitrij asked on 17 Apr 2015, 08:48 AM

Hey guys,

We have a big problem compiling Kendo templates which contain other Kendo widgets, e.g. a Grid.
We have the following template (simplified):

<script id="myTemplate" type="text/x-kendo-template">
@(Html.Kendo().Grid<MyViewModel>()
  .Name("myGrid")
  .Columns(columns =>
  {
     columns.Bound(c => c.Name);
  })
)
</script>

The original template contains other dynamic data-bound values, e.g. "#=Id#"... thus we need a template approach! Now we want to compile this template, because we need to show it as content of a window:

<script type="text/javascript">
    var myTemplate = kendo.template($("#myTemplate").html());
</script>

This should work fine, but Kendo gives us invalid JavaScript when compiling:

Invalid template... Generated code: 
 
var $kendoOutput, $kendoHtmlEncode = kendo.htmlEncode;with(data){$kendoOutput='<div class="k-widget k-grid" id="myGrid"><table><colgroup><col /></colgroup><thead class="k-grid-header"><tr><th class="k-header" data-field="Name" data-index="0" data-title="Name" scope="col"><span class="k-link">Name</span></th></tr></thead><tbody><tr class="k-no-data"><td colspan="1"></td></tr></tbody></table></div><script>\n\tjQuery(function(){jQuery("';myGrid").kendoGrid({"columns":[{"title":"Name","field":"Name","encoded":true}],"scrollable":false,"autoBind":false,"dataSource":{"type":(function(){if(kendo.data.transports['aspnetmvc-server']){return 'aspnetmvc-server';} else{throw new Error('The kendo.aspnetmvc.min.js script is not included.');}})(),"transport":{"read":{"url":""},"prefix":"channelsAssignGrid-"},"serverPaging":true,"serverSorting":true,"serverFiltering":true,"serverGrouping":true,"serverAggregates":true,"filter":[],"schema":{"data":"Data","total":"Total","errors":"Errors","model":{"fields":{"Name":{"type":"string"}}}}}});});
       ;$kendoOutput+=;}return $kendoOutput;
In this code, e.g. jQuery("';myGrid") is emitted as wrong JS code...

 

Any ideas/solutions for this? I think we're not the first discovering this problem... is there any straight forward solution?

 

Thanks, Dimitrij

5 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 21 Apr 2015, 06:30 AM

Hello Dimitrij,

The question is answered on the support thread on the same topic. The ToClientTemplate method of the widget should be invoked.

Regards,
Dimiter Madjarov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Rajan
Top achievements
Rank 1
answered on 21 Sep 2016, 02:33 PM
Hi,

I am getting the invalid Template Error while trying to open the nested grid in kendo grid control.
After lots of findings I have come to know that error is coming because grid's one column contains the data with "#" inside it.
I have done lots of R&D to handle this but did not succeed.

Please help me in the concerned issue.
0
Maria Ilieva
Telerik team
answered on 26 Sep 2016, 07:54 AM
Hi Rajan,

From the error message it seems that the reason for the problem is the AntiXssEncoder which is enabled in the Web.config httpRuntime configuration:

<httpRuntime targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
The spaces in the attributes are encoded and the "#" character is included which breaks the templates parsing. Removing it should resolve the problem. 

Regards,
Maria Ilieva
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Rolston
Top achievements
Rank 1
answered on 28 May 2019, 02:48 PM
Hi Maria, I'm also having same error. that's a cross origin attack security module, i don't thinks its safe to remove it. is there any other way around this issue?
0
Tsvetina
Telerik team
answered on 30 May 2019, 08:47 AM
Hi Rolston,

This error could have different causes and many of them can be addressed without disabling the AntiXssEncoder. Could you copy the full error message that you see in the browser console (including the stack trace) as well as the current declaration of the template that fails to load?

Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Dimitrij
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Rajan
Top achievements
Rank 1
Maria Ilieva
Telerik team
Rolston
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or