Search code examples
javascriptc#jquery-mobilejquery-pluginsjquery-jtable

Jtable An error occured while communicating to the server. - post 500 error


when i am adding a new record i have the above error below is my code, i am stuck done some search on google but i am going nowhere i would be greateful if someone can point me in the right direction.

 $('#dataContent').jtable({
            title: 'Data List',
            paging: true,
            pageSize: 5,
            actions: {
                listAction:'/Test.aspx/GetAllCars',
                createAction: 'Test.aspx/CreateCar'

            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                Make: {
                    title: 'Make',
                    width: '20%'
                },
                Model: {
                    title: 'Model',
                    width: '20%'
                },
                Engine: {
                    title: 'Engine',
                    width: '20%'
                },
                Year: {
                    title: 'Year',
                    width: '20%'
                }
            }

        });

        $('#dataContent').jtable('load');

    });


    [WebMethod(EnableSession = true)]
    public static Object CreateCar(Car c) {
        try {
            bool addresult = new CarRepo().CreateCar(c);
            return new { Result = "OK" };

        }
        catch (Exception ex) {
            return new { Result = "ERROR", Message = ex.Message };
        }

    }


 public bool CreateCar(Car c) {

        using(var context = new DAL.DbAccess.DataContext()) {
            try {
              var Irepo = new DAL.Repository.MainRepository<Car>(context);
              Irepo.Insert(c);
              return true;
            } catch(Exception ex) {
                ex.ToString();
                return false;
            }

        }
    }

POST http://localhost:51598/Test.aspx/GetAllCars

200 OK 4ms jquery-....min.js (line 3) POST http://localhost:51598/Test.aspx/CreateCar

500 Internal Server Error 7ms jquery-....min.js (line 3) HeadersPostResponseJSON

{"Message":"Invalid web service call, missing value for parameter: \u0027c\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}


Solution

  • find the problem it should be

         [WebMethod(EnableSession = true)]
         public static Object CreateCar(Car **record**) {
             try {
                bool addresult = new CarRepo().CreateCar(record);
                return new { Result = "OK" };
    
            }
            catch (Exception ex) {
                return new { Result = "ERROR", Message = ex.Message };
            }
    
        }