编辑jqGrid并将数据发送到.net MVC Webservice



在尝试从jqGrid保存行数据时,我的web服务设置似乎有问题。返回的数据很好;网格很好地加载了数据,当我单击铅笔时,编辑框显示得很好。我已经使用IE开发人员工具检查了请求体,它显示的数据如下:Step_Number=1&oper=edit&id=1我知道在我得到这个方法设置的方式和它被调用的方式中缺少了一些东西,但我不能为我的生命找到我正在寻找的答案。

我需要什么格式的数据JSON和发送它,我有什么在我的。net方法接受数据?

谢谢你提供的任何帮助。

[WebInvoke(Method = "POST", UriTemplate = "/Save/JSA", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string UpdateRecord()
{}
**Update** This is the one that works
[WebInvoke(Method = "POST", UriTemplate = "/Save/JSA", BodyStyle = WebMessageBodyStyle.Wrapped,  RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string UpdateJSA(string Step_Number, string Step_Description, string oper, string id)
{}

当我使用上面的,函数工作,但我没有得到数据。当我输入一个参数时,我的代码似乎就坏了。下面是我使用的jqGrid代码:

$.getJSON('FileServices/Get/JSA/' + id, function (data) {
$("#list").jqGrid({
    url: 'FileServices/GetList/JSA',
    cellEdit: true,
    editurl: 'FileServices/Save/JSA',
    //serializeRowData: function (data) { return JSON.stringify(data); },
    datatype: 'local',
    gridComplete: function () {
            $("#list").jqGrid('setGridParam', {}).trigger("reloadGrid");
    },
    onSelectRow: function (rowid, status) {
    },
    loadComplete: function (data) {
            var det = $("#details");
            $("#list").setGridWidth(det.width() - 18, true);
    },
    colNames: ['Id', 'Step Number', 'Step Description'],
    colModel: [
      { name: 'Id', index: 'Id', width: 30, sortable: false, hidden: true },
      { name: 'Step_Number', editable: true,  index: 'Step_Number', align: 'center', width: 50,  fixed: true, resizable: false, sortable: false, title: false, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal; vertical-align: top;' } },
      { name: 'Step_Description', index: 'Step_Description', sortable: false, width: 400, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal; vertical-align: top;' } }
    ],
    pager: '#pager',
    rowNum: 5,
    rowList: [5, 10, 15, 20, 25, 30, 50],
    sortname: 'Id',
    height: 'auto',
    rownumbers: true,
    autowidth: true,
    forceFit: true,
    shrinkToFit: true,
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    hidegrid: false,
    caption: ''
});
$.extend($.jgrid.edit, {
    ajaxEditOptions: { contentType: "application/json" },
    recreateForm: true,
    serializeEditData: function (postData) {
        return JSON.stringify(postData);
    }
});
var thegrid = $("#list");
for (var i = 0; i < data.details.length; i++) {
    thegrid.addRowData(i + 1, data.details[i]);
}
thegrid.navGrid("#pager");
});

您发布的不是所有必需的代码。你写的是"当我点击铅笔时",所以我猜你在某个地方使用了navGrid,但是如何使用以及使用哪些参数?不管怎样,你把jQuery.jgrid.edit设置错了。代码应该是这样的:

$.extend($.jgrid.edit, {
    ajaxEditOptions: { contentType: "application/json" },
    recreateForm: true,
    serializeEditData: function (postData) {
        return JSON.stringify(postData);
    }
});

最新更新