asp.net-mvc - 为什么 `data(“kendogrid” )` 未定义?

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

我是 kendo.ui 的初学者,我编写了这段代码来创建 kendo.ui.grid

@(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))
    )
)

当用户单击网格中的编辑按钮时,它将在 kendo.ui.window 中显示编辑 View ,用户可以编辑数据。

@(Html.Kendo().Window().Name("Details")
    .Title("Customer Details")
    .Visible(false)
    .Modal(true)
    .Height(400)
    .Draggable(true)
    .Width(300)
    .Events(events => events.Close("onClose"))
)

<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>


<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.center().open();
    }

    function onClose(e) {
        var grid = $("#Grid").data("kendoGrid").dataSource.read();

    }

</script>

但是在onClose方法中$("#Grid").data("kendoGrid")未定义,请帮助我,谢谢大家

最佳答案

尝试窗口加载事件

$(window).load(function () {
var grid = $("#grid").data("kendoGrid");

这对我有用。

关于asp.net-mvc - 为什么 `data(“kendogrid” )` 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18175850/

相关文章:

javascript - TypeError : this. $refs.datasource.fetch 不是函数

javascript - Chrome 控制台 - 这个代表 Kendo UI 小部件的东西实际上意味着什么?

javascript - 获取所有选中的子项目 Kendo Grid

jquery - 带滚动条的 Kendo UI 网格的延迟加载

c# - 数据存储查询数组

c# - 在此上下文中没有响应

javascript - 在 Kendo Grid 上下降时在两者之间插入记录

c# - asp.net mvc c# 随机生成相同的数字

asp.net-mvc - 访问已登录用户的 Azure Blob 存储

kendo-ui - 在 DetailExpand 事件中选择剑道网格行