【发布时间】:2020-09-19 10:45:02
【问题描述】:
我将 asp.net 核心用于我的项目后端,但我的方法没有获取我通过 jQuery ajax 发送给他们的数据
这些是我发送数据的脚本:
function ChangeCount(productId, count) {
$.ajax({
type: "POST",
data: JSON.stringify({ ProductId: productId, Count: count }),
url:'@(Url.Action("ChangeOrderCount", "Payment"))',
contentType: "application/json;",
dataType:"json"
}).done(function (result) {
if(!isNaN(result)) {
var NewProductCount = parseInt(result)
if (NewProductCount == 0) {
$("#Order-" + productId).fadeOut();
}
else {
$("#OrderCount-" + productId).html(NewProductCount);
}
} else {
alert(result);
}
});
}
这是我的后端代码:
public JsonResult ChangeOrderCount(int ProductId, int Count)
{
string userId = userRepository.GetUserByEmail(User.Identity.Name).Id;
bool result = bascketrepository.AddToCart(userId, ProductId, Count);
if (result)
return Json(bascketrepository.GetProductOrderCountInCurrentBascket(userId,ProductId));
else
return Json("خطایی رخ داده است");
}
【问题讨论】:
-
你能做两件事吗?首先向我们展示后端方法代码。第二个在你的
ChangeCount函数开始时,做alert(productID)和alert(count) -
我将它们登录到控制台然后我确定我的 js 函数获取了值并发送了 ajax 请求但它不发送数据!
-
您可以将代码添加为文本而不是图像吗?
标签: javascript jquery asp.net ajax asp.net-core