【发布时间】:2019-10-14 23:55:39
【问题描述】:
“pid”值工作正常,“qty”值在控制器上显示为“0”。
我 100% 确定问题出在查询字符串上。
这里是 ajax 和 jquery 代码:
$(".cartquantity").change(function () {
var tblrow = $(this).parents(".datarow");
var amtcell = $("#amtcell").text();
var pid = $(this).data("pid");
var qty = $(this).val();
var price = $("#prc").text();
$.ajax(
{
url: "/cart/UpdateQuantity?pid=" + pid + "&qty" + qty //here problem occurs
}
).done(function (result) {
if (qty < 1)
tblrow.remove();
else
amtcell.text(price * qty);
$("#cartitems").text(result.Items)
});
});
Controller Code:
int pid = Convert.ToInt32(Request.QueryString["pid"]);
int qty = Convert.ToInt32(Request.QueryString["qty"]); //showing "0"
请告诉我通过查询字符串传递值的正确语法是什么。因为 qty 变量显示正确的值,但是当数据通过查询字符串时,它变为 0。
【问题讨论】:
-
查询字符串中的
qty缺少=,应该是"&qty=" + qty -
请添加一次` url: "/cart/UpdateQuantity?pid=" + pid + "&qty=" + qty`
标签: javascript jquery ajax asp.net-mvc