简体   繁体   中英

Kendo MVC Grid ClientTemplate will lead to “Field not defined”

I have a kendo MVC Grid which read action can be done successfully

 @(Html.Kendo().Grid<MyModel>() .Name("Name") .AutoBind(false) .Columns(columns => { ... columns.Bound(c => c.ItemCode).ClientTemplate("#= ItemCode #").Title("Item").Width(300); }) .Pageable(page => { page.Enabled(true); }) .Scrollable(s => s.Height(400)) .Sortable(s => s.Enabled(false)) .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("MaterialFormEditor").Window(w => { w.Title(""); w.Width(700); }).DisplayDeleteConfirmation(false)) .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .Model(model => model.Id(p => p.JobNo)) .Read(read => read.Action(...) .ServerOperation(true) ) ) 

  public class MyModel { public string ItemCode; } 

(Above code is simplified, so the ClientTemplate content is simply the field value itself, yet the problem still can be reproduced)

Now the problem is, when I click the "Add new record" button, a javascript error comes out and no window is popped up.

The error said: Uncaught ReferenceError: ItemCode is not defined

Yet when I delete the .ClientTemplate() , everything goes right.

What is the cause of the error and how can I solve it?

Old question, I know...

I had a similar issue and had to add backslashes to get it to work:

    columns.Bound(c => c.ItemCode).ClientTemplate("\\#= ItemCode \\#").Title("Item").Width(300);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM