开发者

Editing jqGrid and sending data to .NET MVC Webservice

I seem to have a problem with the setup of my web service when trying to save row data from my jqGrid. The data comes back fine; the grid loads the data fine and the edit box displays fine when I click the pencil. I've checked the Request body using IE Developer tools and it shows data like: Step_Number=1&oper=edit&id=1 I know there is something missing in the way I've got this method setup and the way it's called but I can't for the life of me find the answers I'm looking for.

What do I need to format the data into JSON and send it and what do I have to have on my .Net method to accept the data?

Thank you for any help you can provide.

[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)
{}

When I use the above, the function works but I get no data. The second I put a parameter, my code just seems to break. Here is my jqGrid code that I'm using:

$.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', alig开发者_C百科n: '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");
});


You posted not all code which is required. You wrote "when I click the pencil" so I suppose that you use navGrid somewhere, but how and with which parameters?... In any way you set jQuery.jgrid.edit in the wrong way. The code should looks about the following:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜