2014-02-12 99 views
2

我在做什麼錯了?我收到以下錯誤。我使用MVC,但不使用MVC包裝。劍道模板在網格中無效

Uncaught Error: Invalid template:' 
<form action="/Intranet/GalleryFile/Edit" data-ajax="true" data-ajax-method="Post" data-ajax-mode="replace" data-ajax-update="#slideoutmenu" id="form1" method="post">      <input type="hidden" id="fileID" name="fileID" value='#= fileID #' /> 
<input type="submit" value="Save" class="btn btn-default" /> 
</form> ' Generated code:'var o,e=kendo.htmlEncode;with(data){o='\n<form action="/Intranet/GalleryFile/Edit" data-ajax="true" data-ajax-method="Post" data-ajax-mode="replace" data-ajax-update="';slideoutmenu" id="form1" method="post">    <input type="hidden" id="fileID" name="fileID" value=';o+='= fileID ';' /> 
      <input type="submit" value="Save" class="btn btn-default" /> 
</form> ;o+=;}return o;' 

的JavaScript:

$(document).ready(function() { 

     var dsGalleryItemFile = new kendo.data.DataSource({ 
      transport: { 
       read: "@Url.Content("~/Intranet/GalleryItemFile/ListFiles/")@Model.galleryItemID" 
      }, 
      // determines if changes will be send to the server individually or as batch 
      batch: false, 
      schema: { 
       model: { 
        id: "fileID", 
        fields: { 
         fileID: { 
          nullable: true 
         }, 
         filename: {}, 
         fileType: { defaultValue: {fileTypeID: 1, fileType: "Web JPEG"} }, 
         fileType: {}, 
         width: { type: "number" }, 
         height: { type: "number" }, 
         } 
        } 
       } 
     }); 

     $("#gvGalleryItemFile").kendoGrid({ 
      columns: [{ 
       field: "filepath", 
       title: "File Upload", 
       width:"250px",//, 
       //template: "<img src='#=filepath.filepath#' />" 
      }, { 
       field: "fileType", 
       title: "File Type", 
       template: "#=fileType.fileType#", 

      }, { 
       field: "width", 
       title: "Width(px)", 
       format: "{0:n0}", 
       width: "110px" 
      }, { 
       field: "height", 
       title: "Height(px)", 
       format: "{0:n0}", 
       width: "110px" 
      }, { 
       field: "fileID", 
       title: "", 
       template: kendo.template($("#gridEditButtonTemplate").html()) 
      }], 
      dataSource: dsGalleryItemFile 
     }); 


    });  

模板:

<script type="text/x-kendo-template" id="gridEditButtonTemplate"> 
     @using (Ajax.BeginForm("Edit", "GalleryFile", null, new AjaxOptions { UpdateTargetId = "slideoutmenu", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" })) 
     { 
      <input type="hidden" id="fileID" name="fileID" value='#= fileID #' /> 
      <input type="submit" value="Save" class="btn btn-default" /> 
     } 
</script> 

這不是甚至達到事物的MVC方面,所以我不包括該代碼。它只是不會將模板讀入我的網格列。

回答

2

#字符在kendo模板中有特殊含義,因此如果您想將其用作常規字符,它必須被轉義。 你Ajax.BeginForm是創建屬性

data-ajax-update="#slideoutmenu" 

這就是傷了你的模板。它應該是

data-ajax-update="\#slideoutmenu" 

我不確定是否有解決方法使用Html助手。最簡單的修復方法是使用純Html代替。