jqgrid通过在aspx文件中使用[WebMethod]

时间:2018-01-04 05:14:33

标签: asp.net jqgrid

我正在为我的项目使用jqgrid。 到目前为止,当我使用ahsx文件时,jqgrid是可以的 但是当我尝试在aspx文件中使用[WebMethod]时,我收到错误500。 这是我的jqgrid设置

            $(document).ready(function () {  
            $("#JQGrid").jqGrid({
                url: 'Testing.aspx/LoadMachineCapacity',
                mtype: 'POST',
                ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                datatype: "json", 
                postData: {}, 
                height: 100,
                autowidth: true, 
                loadtext: "Loading...", 
                colModel: [
                    {
                        name: 'MACHINEID',
                        index: 'MACHINEID',
                        label: 'Machine ID',
                        sortable: false,
                        editable: false
                    },
                    {
                        name: 'ISACTIVE',
                        index: 'ISACTIVE',
                        label: 'IS ACTIVE',
                        sortable: false,
                        editable: true
                    }], 
                loadonce: true,
                serializeGridData: function (postData) {
                    return JSON.stringify(postData);
                },
                multiselect: false, 
                caption: 'Machines',  
                pager: '#JQGridPager', 
                pgbuttons: true, rowNum: 10, rowList: [10, 20, 30], 
                rownumbers: true,
                viewrecords: true
                , cellEdit: true
                , afterEditCell: function (rowid, cellname, value, iRow, iCol) {
                    alert(value);
                },
                loadError: function (jqXHR, textStatus, errorThrown) {
                    alert('HTTP status code: ' + jqXHR.status + '\n' +
                        'textStatus: ' + textStatus + '\n' +
                        'errorThrown: ' + errorThrown + '\n' +
                        'errorDesc.: ' + jqXHR.responseText); 
                }
            });
            $("#JQGrid").navGrid('#JQGridPager',
                { view: false, edit: false, search: true, add: false, del: false, refresh: true }
            ); 
        }); 

这是我的服务器端代码

  [WebMethod] 
public static string LoadMachineCapacity(string pageIndex)
{
    string Result = "";

    try
    {
        string strOracleCnnString = ConfigurationManager.ConnectionStrings["PKERP"].ConnectionString;
        OracleConnection oracleConn = new OracleConnection(strOracleCnnString);


        string strSQL = " SELECT *  " +
                        " FROM  T_CT_MCCP  " ;

        OracleDataAdapter dataAdapter = new OracleDataAdapter(strSQL, oracleConn);
        DataTable dataTable = new DataTable();
        dataAdapter.Fill(dataTable);


        Result = JsonConvert.SerializeObject(dataTable, Formatting.Indented);
    }
    catch (Exception e)
    {
        Result = JsonConvert.SerializeObject(e.Message, Formatting.Indented);
    }

    return Result;
}

提前感谢。 托马斯

1 个答案:

答案 0 :(得分:0)

Webmethod有一个参数。

但是,您的jqGrid设置未在postData配置。

更改为postData:{pageIndex:“blabla”}。