【问题标题】:Kendo Template Invalid in Grid网格中的剑道模板无效
【发布时间】:2014-02-12 17:19:03
【问题描述】:

我做错了什么?我收到以下错误。我正在使用 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 方面,所以我不包括该代码。它只是不会将模板读入我的网格列。

【问题讨论】:

    标签: asp.net-mvc kendo-ui kendo-grid kendo-template


    【解决方案1】:

    # 字符在剑道模板中具有特殊含义,因此如果您想将其用作常规字符,则必须对其进行转义。 您的 Ajax.BeginForm 正在创建属性

    data-ajax-update="#slideoutmenu"
    

    这会破坏您的模板。应该是

    data-ajax-update="\#slideoutmenu"
    

    我不确定是否可以使用 Html 帮助程序解决此问题。最简单的解决方法是改用纯 Html。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多