在Kendo UI和Web API中进行InCell编辑

时间:2014-08-23 13:41:19

标签: asp.net-web-api kendo-grid

我是Web APIKendo UI的新手。我的要求是InCell编辑。我已通过以下参考链接实现了此功能。但我的问题是在控制器操作方法我得到的员工数为0.我不是任何其他东西意味着编辑行。

http://demos.telerik.com/kendo-ui/grid/editing

http://demos.telerik.com/aspnet-mvc/grid/editing

和我尝试下面的参考的另一种方式。但是在JQuery中我也得到了我更新的行。但是当通过控制器中的AJAX调用将数据传递给控制器​​时,我的计数为0.请帮助。

  http://stackoverflow.com/questions/17033025/kendo-grid-batch-editing-making-a-single-call-to-save

这是我的代码:

 var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/api/Employee/GetEmployee",
                    dataType: "json"
                },
                create: {
                    url: "/api/Employee/CreateEmployee",
                    dataType: "json",
                    type: "POST",
                    complete: function (jqXhr, textStatus) {
                        // Do something
                    }
                },
                update: {
                    url: "/api/Employee/Update",
                    dataType: "json",
                    type: "POST",   
                    complete: function (jqXhr, textStatus) {     
                         // Do something
                    }
                },
                destroy: {
                    url: "/api/Employee/DeleteEmployee",
                    dataType: "json",
                    type: "DELETE",
                    complete: function (jqXhr, textStatus) {
                         // Do something
                    }
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            },
            batch: true,
            pageSize: 12,
            schema: {
                model: {
                    id: "Id",
                    fields: {
                        Id: { editable: false, type: "number" },
                        EmployeeId: {
                            editable: true, type: "text", validation: {required: true },
                        },
                        EmployeeName: { validation: { required: true } }
                    }
                }
            }
        });
        if (container.find('#gridEmployee').data().kendoGrid)
            container.find('#gridEmployee').data().kendoGrid.destroy();
        container.find("#gridEmployee").kendoGrid({
            dataSource: dataSource,
            pageable: true,
           // toolbar: [{ text: "Add new Employee", className: "btn btn-primary grid-add-new-record" }, { text: "Save", className: "btnKendoUiSave" }],
            toolbar: ["create", "save", "cancel"],
            columns: [
                  {
                      command: [
                       //define the commands here
                       { name: "edit", text: " " }, { name: "destroy", text: " " }, { name: "update", text: " ", click: showDetails }], width: "200px"
                  },
                  { field: "EmployeeId", title: "Employee Id", format: "{0:0}", headerAttributes: { "data-localize": "FIELD_NUMBER" } },
                  { field: "EmployeeName", title: "Employee Name", headerAttributes: { "data-localize": "FIELD_NAME" } },
            ],
            editable: true,

        });

Web API Controller:

 [HttpPost]
        public System.Web.Mvc.JsonResult Update([System.Web.Mvc.Bind(Prefix = "models")]List<PlantEmployeeModel> Employees)
{
//
}

0 个答案:

没有答案