【发布时间】:2020-11-16 19:49:32
【问题描述】:
我创建了一个执行 ajax 调用的函数,但在调用它时出现此错误。
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
这是代码:
$('#Item').change(function () {
debugger
$('#Price').empty();
$('#Description').empty();
$('#Quantity').val("");
$('#Amount').val("");
$.ajax({
type: "GET",
url: "/Payments/GetItemByIdForEdit/",
datatype: "Json",
data: { id: $('#Item').val() },
success: function (data) {
debugger
$("#Price").val(data.ItemUnitPrice);
$("#Description").val(data.itemDescription);
//$("#productId").text(value.Id);
}
});
});
这是操作代码:
public JsonResult GetItemByIdForEdit(string id)
{
if (id != "")
{
int productId = Convert.ToInt32(id);
var product = _unitOfWork.Items.GetItemSingleOrDefault(productId);
return Json(product, JsonRequestBehavior.AllowGet);
}
else
{
var product = new Item();
//product.Description = "";
//product.UnitPrice = 0.0;
return Json(product, JsonRequestBehavior.AllowGet);
}
}
我看不出问题出在哪里?
你有什么解决办法吗?
谢谢
这是调试器模式的结果:
【问题讨论】:
-
当您使用浏览器访问该 URL 时会发生什么?
-
转到此操作
public JsonResult GetItemByIdForEdit(string id)然后在触发此功能后,成功功能不会触发success: function (data) { debugger $("#Price").val(data.ItemUnitPrice); $("#Description").val(data.itemDescription); //$("#productId").text(value.Id); }并给我该错误 -
成功函数的主要问题在调用
GetItemByIdForEdit后没有触发
标签: c# ajax asp.net-mvc