编辑jqGrid的和发送数据到.NET MVC web服务 [英] Editing jqGrid and sending data to .NET MVC Webservice

查看:302
本文介绍了编辑jqGrid的和发送数据到.NET MVC web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎与我的Web服务的设置有问题试图从我的jqGrid的保存行数据时。数据回来的罚款;网格加载数据精细和编辑框显示正常,当我点击的铅笔。我使用的是IE Developer工具检查请求体,它显示了相似的数据: STEP_NUMBER = 1&安培; OPER =编辑和ID = 1 我知道有一些东西在路上失踪,我得到这个方法设置和它的调用方式,但我不能为我的生活中找到我要找的答案。

做什么,我需要的数据格式化为JSON并将其发送和我有什么要对我的.NET方法来接受数据?

感谢您的帮助,您可以提供。

  [WebInvoke(方法=POST,UriTemplate =/保存/ JSA,BodyStyle = WebMessageBodyStyle.Bare,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)
公共字符串UpdateRecord()
{}

**更新**这是一个工程
[WebInvoke(方法=POST,UriTemplate =/保存/ JSA,BodyStyle = WebMessageBodyStyle.Wrapped,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)
公共字符串UpdateJSA(字符串STEP_NUMBER,串Step_Description,串OPER,字符串ID)
{}
 

当我使用上面的,功能的作品,但我没有得到任何数据。我把一个参数的第二个,我的code只是似乎打破。下面是我用我的jqGrid的code:

  $。的getJSON(FileServices /获取/ JSA /+ ID,功能(数据){
$(#列表)。jqGrid的({
    网址:FileServices /的GetList / JSA,
    cellEdit:真正的,
    editurl:FileServices /保存/ JSA,
    // serializeRowData:功能(数据){返回JSON.stringify(数据); },
    数据类型:本地,
    gridComplete:函数(){
            $(#列表)jqGrid的('setGridParam',{})触发(reloadGrid)。
    },
    onSelectRow:功能(ROWID,状态){
    },
    loadComplete:功能(数据){
            VAR DET = $(#范围);
            $(#列表)setGridWidth(det.width() -  18,真正的);
    },
    colNames:['身份证','步数,步骤说明'],
    colModel:
      {名字:'身份证',索引:'身份证',宽度:30,排序:假的,隐藏的:真正的},
      {名字:STEP_NUMBER,可编辑:真正的,索引:STEP_NUMBER,对齐:中心,宽度:50,固定:真正的,可调整大小:假的,可排序的:假的,标题:假的,cellattr:功能(ROWID,电视,rawObject,厘米,RDATA){return'的风格=白色空间:正常;垂直对齐:首位; }},
      {名字:Step_Description,索引:Step_Description,排序:假的,宽度:400,cellattr:功能(ROWID,电视,rawObject,厘米,RDATA){return'的风格=白色空间:正常;垂直对齐: 最佳;' }}
    ]
    寻呼机:#pager,
    的rowNum:5,
    rowList:[5,10,15,20,25,30,50],
    sortname:'身份证',
    高度:自动,
    rownumbers:真正的,
    autowidth:真正的,
    forceFit:真正的,
    shrinkToFit:真正的,
    排序顺序:升序,
    viewrecords:真正的,
    gridview的:真正的,
    hidegrid:假的,
    标题: ''
});

$ .extend($。jgrid.edit,{
    ajaxEditOptions:{的contentType:应用/ JSON的},
    recreateForm:真正的,
    serializeEditData:功能(POSTDATA){
        返回JSON.stringify(POSTDATA);
    }
});

VAR thegrid = $(#名单);

对于(VAR I = 0; I< data.details.length;我++){
    thegrid.addRowData第(i + 1,data.details [I]);
}

thegrid.navGrid(#寻呼机);
});
 

解决方案

您没有发布这是需要所有code。你写了当我点击的铅笔,所以我假设你使用 navGrid 的地方,但如何与哪些参数?......在任何方式,您设置 jQuery.jgrid.edit 在错误的道路。在code看起来应该对以下内容:

  $。延长($。jgrid.edit,{
    ajaxEditOptions:{的contentType:应用/ JSON的},
    recreateForm:真正的,
    serializeEditData:功能(POSTDATA){
        返回JSON.stringify(POSTDATA);
    }
});
 

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', 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");
});

解决方案

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);
    }
});

这篇关于编辑jqGrid的和发送数据到.NET MVC web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆