【问题标题】:jqgrid by using [WebMethod] inside aspx filejqgrid 通过在 aspx 文件中使用 [WebMethod]
【发布时间】:2018-01-04 05:14:32
【问题描述】:

我在我的项目中使用 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;
}

提前致谢。 托马斯

【问题讨论】:

    标签: asp.net jqgrid


    【解决方案1】:

    Webmethod处有参数。

    但是,您的 jqGrid 设置未配置为 postData

    更改为 postData: {pageIndex: "blabla"}。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 2021-10-10
      • 1970-01-01
      • 2014-05-30
      相关资源
      最近更新 更多