如何在kendo.ui.grid中创建自定义kendo.ui.Window进行编辑

Pou*_*uya 8 asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc

我是kendo.Ui的首发,我为创建网格编写了这段代码

@(Html.Kendo().Grid<BrandViewModel>(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.BrandName);
        columns.Bound(p => p.BrandAbbr);
        columns.Bound(p => p.SrcImage);

        columns.Command(command => command.Custom("Edit").Click("editItem"));

    })

    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("CustomCommand_Read", "Brand"))
         .Model(model => model.Id(p => p.Id))

               )
)
Run Code Online (Sandbox Code Playgroud)

我想当用户点击在kendo窗口中Edit打开的按钮时Edit view我写这段代码

@(Html.Kendo().Window().Name("Details")
    .Title("Customer Details")
    .Visible(false)
    .Modal(true)
    .Draggable(true)

    .Width(300)
)



<script type="text/x-kendo-template" id="template">
    <div id="details-container"> <!-- this will be the content of the popup -->
        BrandName: <input type='text' value='#= BrandName #' />

    </div>
</script>
Run Code Online (Sandbox Code Playgroud)

和java脚本代码:

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

    function editItem(e) {
        e.preventDefault();

        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

        $("#Details").data("kendoWindow").refresh({
            url: "/Brand/Edit/" + dataItem.Id
        });
        $("#Details").data("kendoWindow").open();



    }
</script>
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常我第一次点击一个按钮,但是当我再次点击时.我遇到了以下错误

0x800a138f - JavaScript runtime error: Unable to get property 'refresh' of undefined or null reference
Run Code Online (Sandbox Code Playgroud)

请帮助我,谢谢大家

Jof*_*ern 4

我记得我在这个控件上也遇到过类似的问题。现在它对我来说适用于以下 Javascript 代码:

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

    $(document).ready(function () {
        windowObject = $("#Details").data("kendoWindow");
    });

    function editItem(e) {
        e.preventDefault();

        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

        windowObject.refresh({
            url: "/Brand/Edit/" + dataItem.Id
        });
        windowObject.open();
    }
</script>
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你 !