Kendo UI Grid内联编辑

时间:2015-07-26 15:54:33

标签: kendo-ui kendo-grid

您好我正在尝试使用kendo网格并且它不起作用,显示网格但没有显示数据。我不知道出了什么问题。我不知道parametersMap是如何工作的。请帮帮我。

控制器

public ActionResult GetGeo(int id) 
{
    var list = data.getGeoList(id);
    return Json(new {list}, JsonRequestBehavior.AllowGet);
}

public ActionResult UpdateGeo(int id)
{
    var success = data.UpdatetGeo(id);
    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

public ActionResult DeleteGeo(int id)
{
    var success = data.DeletetGeo(id);
    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

public ActionResult CreateGeo(GeoContent model)
{
    var success = data.CreateGeo(model);
    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

这是脚本

<script>
$(document).ready(function () {

        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/Home/GetGeo/",
                    dataType: "json",
                    contentType: "application/json",
                    data: {id:5}

                },
                update: {
                    url:  "/Home/UpdateGeo",
                    dataType: "json",
                    contentType: "application/json"
                },
                destroy: {
                    url:  "/Home/DeleteGeo",
                    dataType: "json",
                    contentType: "application/json"
                },
                create: {
                    url:  "/Home/CreateGeo",
                    dataType: "json",
                    contentType: "application/json"
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            },
            batch: true,
            pageSize: 20,
            schema: {
                model: {
                    id: "GeoId",
                    fields: {
                        GeoId: { editable: false, nullable: true },
                        ContentId: { editable: false, nullable: true },
                        Latitude: { type: "number", validation: { required: true, min: 1 } },
                        Longitude: { type: "number", validation: { required: true, min: 1 } },

                    }
                }
            }
        });

    $("#grid4").kendoGrid({
        dataSource: dataSource,
        navigatable: true,
        pageable: true,
        height: 550,
        toolbar: ["create", "save", "cancel"],
        columns: [
            { field: "Latitude", title: "Latitude", width: 120 },
            { field: "Longitude", title: "Longitude", width: 120 },
            { command: "destroy", title: "&nbsp;", width: 150 }],
        editable: true
    });
});

Json数据返回: http://localhost:53232/Home/GetGeo?id=5

{"list": [
  {
    "GeoId":1,
    "ContentId":5,
    "Latitude":4.716168,
    "Longitude":-70.78373
  },{
    "GeoId":2,
    "ContentId":5,
    "Latitude":4.718171,
    "Longitude":-70.76253
  }
]}

1 个答案:

答案 0 :(得分:0)

由于您的数据实际上嵌套在list元素上,因此您需要添加到架构data: "list"。它应该看起来像:

schema: {
    data:"list",
    model: {
        id: "GeoId",
        fields: {
            GeoId: { editable: false, nullable: true },
            ContentId: { editable: false, nullable: true },
            Latitude: { type: "number", validation: { required: true, min: 1 } },
            Longitude: { type: "number", validation: { required: true, min: 1 } }

        }
    }
}