kendo Ui - Grid不会调用控制器

时间:2014-08-07 09:51:34

标签: javascript kendo-ui kendo-grid kendo-asp.net-mvc kendo-datasource

我的KendoUi网格有点问题。这很简单:

JS档案

 $("#gridPlannif").kendoGrid({
    datasource: ds_VEHICULE_SANSDATEFIN,
    height: 200,
    toolbar: ["create"],
    sortable: true,
    filterable: true,
    scrollable: true,
    columns: [{
        field: "sDateArriveePrevue",
        title: "Arrivée à partir du",
    }, {
         [... some columns... ]
    },{
        command: ["edit", "destroy"], title: " ", width: "200px" }
    ],
    editable: {
        mode: "popup",
        [... some configurations ... ]
    }
});

的Controler

 public ActionResult UpdateVehicule([DataSourceRequest]DataSourceRequest request, Planification vehicule)
    { 
        try
        {
            if (this.ModelState.IsValid)
            {
              [...]
            }
            else
            {
               [...]
            }
            return Json(new[] { vehicule }.ToDataSourceResult(request, ModelState));
        }
        catch (Exception e)
        {
            return Json(new[] { vehicule });
        }
    }

查看(.ascx)

[...]
<script>
 ds_VEHICULE_SANSDATEFIN = new kendo.data.DataSource({
            autoSync: true,
            transport: {
                read: {
                    url: '<%= Url.Action("GetVehicules_SansDateFin", "Plannification") %>'
                },
                update: {
                    url: '<%= Url.Action("UpdateVehicule", "Plannification") %>'
                },
                destroy: {
                    url: '<%= Url.Action("DeleteVehicule", "Plannification") %>'
                },
                create: {
                    url: '<%= Url.Action("AddVehicule", "Plannification") %>'
                }

            }
        });

</script>
[...]

问题

- &GT;第一个问题:数据源定义不起作用。我必须在网格初始化后执行该指令:

$("#gridPlannif").data("kendoGrid").setDataSource(ds_VEHICULE_SANSDATEFIN);
$("#gridPlannif").data("kendoGrid").dataSource.read();
$("#gridPlannif").data("kendoGrid").refresh();

由于这一点,网格正确显示数据。

- &GT;第二个问题,最重要的是: &#34;添加&#34;,&#34;编辑&#34;和&#34;销毁&#34;不会打电话给控制器。使用firebug,我看不到控制器的呼叫,我不知道为什么。我在同一页面上使用Scheduler组件并且它可以工作,它在控制器上使用相同的功能来添加/更新/删除。

有人有建议吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

这听起来像是你的JavaScript库代码“$(”#gridPlannif“)。kendoGrid({”不包含在document.ready中(假设你也在使用jQuery)并在View的JavaScript代码之前加载(类库)在查看代码之前加载,除非另有说明。)

因此,请务必如下所示打包您的JavaScript库代码:

$(function() {  // This is jQuery shorthand for document.ready
    $("#gridPlannif").kendoGrid({
        datasource: ds_VEHICULE_SANSDATEFIN,
        height: 200,
        toolbar: ["create"],
        sortable: true,
        filterable: true,
        scrollable: true,
        columns: [{
            field: "sDateArriveePrevue",
            title: "Arrivée à partir du",
        }, {
             [... some columns... ]
        },{
            command: ["edit", "destroy"], title: "&nbsp;", width: "200px" }
        ],
    editable: {
        mode: "popup",
        [... some configurations ... ]
    }
});

这将允许渲染所有View页面代码,包括内联&lt; script&gt;在尝试连接Kendo Grid之前定义的块。所有这些都是为了确保在尝试从Kendo Grid初始化中调用数据源之前存在数据源。

相关问题