当我添加一条新记录时,我有以下错误是我的代码,我在谷歌上做了一些搜索,但我无处可去,如果有人可以指出我正确的方向,我会很沮丧。
$('#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(第3行) 发布http://localhost:51598/Test.aspx/CreateCar
500内部服务器错误 7毫秒 jquery -.... min.js(第3行) HeadersPostResponseJSON
{“Message”:“无效的Web服务调用,缺少参数值:\ u0027c \ u0027。”,“StackTrace”:“at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target,IDictionary {{ System.Web.Script.Script.Services.RestHandler.ExecuteWebServiceCall上的System.Web.Script.Ser.Services.RestHandler.InvokeMethod(HttpContext上下文,WebServiceMethodData methodData,IDictionary`2 rawParams)\ r \ n中的1}} 2个参数)\ r \ n (HttpContext context,WebServiceMethodData methodData)“,”ExceptionType“:”System.InvalidOperationException“}
答案 0 :(得分:0)
500是服务器意外条件代码。这看起来不像JavaScript问题。您正在使用.Net aspx页面。您可能希望确保IIS服务器已设置并正常运行。
答案 1 :(得分:0)
找到它应该是的问题
[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 };
}
}