你好我有一个ajax调用:
$.ajax({
url: "/Orders/CheckIfExists",type: "GET",contentType: "application/json; charset=utf-8",data: {
catalogNumber: viewmodel.catalogNumber,quantity: viewmodel.quantity
},error: function (data) {
alert("wystąpił nieokreślony błąd " + data);
},success: function (data) {
if(data.ok)
{
alert(data.quantity)
}
}
})
});
这是控制器方法:
public JsonResult CheckIfExists(string catalogNumber,int quantity)
{
List>> where = new List>>();
where.Add(w=>w.DeviceUsage.UserId==1);
where.Add(w => w.Project == null);
where.Add(w => w.Device.CatalogNo == catalogNumber);
var result = unitOfWork.deviceInstanceRepository.Get(where)
.GroupBy(w => new
{
DeviceId = w.DeviceId,CatalogName = w.Device.CatalogNo,})
.Select(s => new
{
Quantity = s.Sum(x => x.Quantity),}).First();
if (result.Quantity >= quantity)
{
return Json(new { ok = true,quantity = result.Quantity});
}
return Json(new { ok = false });
}
但我总是得到内部500错误.
通过方法接收数据,所有计算都可以.我在例子中编写了返回JSON.
我犯了哪个错误?