Kendo无法获取未定义或空引用的属性“数据”

时间:2015-11-13 20:45:00

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

我正在使用Angular的Kendo UI网格。我正在尝试向我的MVC控制器发送网格更新,但是当我单击网格中的“更新”按钮时,我收到错误“无法获取未定义或空引用的属性'数据”

这是我网格的Angular控制器代码:

  $scope.gridOptions = {
        dataSource: new kendo.data.DataSource({
            transport: {
                read: {
                    method: "GET",
                    url: "/SSQV4/SSQV5/Search/GetBusinessUnits"
                },

                update: {
                    method: "POST",
                    url: "/SSQV4/SSQV5/Operator/UpdateBusinessUnit"
                }
            },
            schema: {
                model: {
                    id: "ProductID",
                    fields: {
                        intOrder: { editable: false },
                        OperatorBusinessUnitID: { editable: false },
                        vchDescription: { editable: true },
                        vchOperatorSystemID: {editable: true}
                    }
                }
          },
            sort: { field: "intOrder", dir: "asc" }
        }),

        batch: false,
        reorderable: true,
        sortable: false,
        editable: "inline",
        columns: [
          { template: '<i class="fa fa-chevron-circle-up" style="cursor:pointer" ng-click="MoveUp(#=OperatorBusinessUnitID#)"></i>&nbsp;&nbsp;&nbsp;<i class="fa fa-chevron-circle-down" ng-click="MoveDown(#=OperatorBusinessUnitID#)" style="cursor:pointer"></i>', title: "List Order", width:100 },
          { field: "intOrder", hidden: true},
          { field: "OperatorBusinessUnitID", title: "Business Unit ID" },
          { field: "vchDescription", title: "Business Unit Name" },
          { field: "vchOperatorSystemID", title: "Operator System ID"},
          {
              command: [
                { name: "edit", text: " " },
                { name: "destroy", text: " " },
              ], title: "Action"
          }
        ]
    };

这是我的MVC控制器方法:

public ActionResult UpdateBusinessUnit(OperatorBusinessUnitModel form)
{
    CompanyClient.UpdateBusinessUnit(form);
    var businessunits = CommonClient.GetBusinessUnitsByMajorID(UserInfo.intMajorID);
    return Json(businessunits, JsonRequestBehavior.AllowGet);
}

1 个答案:

答案 0 :(得分:0)

这里有两个问题导致了我的问题。首先,该方案将产品ID作为ID,它应该是OperatorBusinessUnitID。 (这就是复制示例所得到的。)问题是我的MVC控制器中的UpdateBusinessUnit方法需要更改为void而不是ActionResult返回整个记录集。它现在似乎正常工作。