我有一个从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 ...});}
在 Controller 中,ActionResult为:
[HttpPost]
public ActionResult GetReportLast5SellAndBuy(string ItemCode)
{ ... somthings ...}
但是,当ActionResult称为“ItemCode”为null时...本章怎么了?
我尝试了此食谱的其他形式,但问题仍然存在。
最佳答案
试试这个:
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: JSON.stringify({ItemCode:itemCode}),
datatype: "JSON",
contentType: "application/json; charset=utf-8",
processData: false
}).done(function (msg) { ... somethings ...});}