【发布时间】:2019-09-04 06:44:51
【问题描述】:
我有一个从 jquery ajax 到 ActionResult 方法的发布请求,如下所示:
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
var GetReportLast5SellAndBuyURL="/Trd/SellInvoice/GetReportLast5SellAndBuy";
itemCode = $(this).val();
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: {ItemCode:itemCode},
//contentType: "application/json; charset=utf-8",
context: this,
processData: false
}).done(function (msg) { ... somethings ...});}
而在控制器中,ActionResult 是:
[HttpPost]
public ActionResult GetReportLast5SellAndBuy(string ItemCode)
{ ... somthings ...}
但是当ActionResult被称为“ItemCode”时为空……这一章有什么问题?
我尝试了这个食谱的不同形式,但问题仍然存在..
【问题讨论】:
-
你试过用引号吗?喜欢
data: {"ItemCode": itemCode}???? -
是的..我试过了
-
您是否验证过 itemCode = $(this).val();返回一些东西,并且开始时还不是 null?
-
是的..它有价值..我检查了它
-
好的最后一件事我知道你试过数据:{'ItemCode='+itemCode}?由于您试图将其作为字符串传递给您的操作结果。
标签: javascript jquery ajax