【发布时间】:2020-05-05 19:04:56
【问题描述】:
我的问题:我正在发送 JSON 数据,但我的 JSON 数据变为“空”?我不明白为什么它会为空。
我阅读了所有文档,但我是 jquery 的新手。 我错过了什么? 我需要为我的控制器发送 JSON 数据。
Index.cshtml:
var UserData = {
"CustomerID": "99999",
"CustomerCode": "0",
"UserID":"127",
"StartDate": "02/09/2019",
"FinishDate": "03/08/2020",
"SuccesID": "1",
"Cash": "1",
"ProblemID": "1",
"PageNo":"1",
"DataNo":"1"
};
var userDataJson = JSON.stringify(UserData);
$.ajax({
type: "POST",
url: "/Problems/Search",
contentType: "application/json",
data: userDataJson,
success: function (msg) {
console.log(msg);
},
error: function (err) {
alert("search error");
}
});
型号:
public class ProblemsInput
{
public string CustomerID { get; set; }
public string CustomerCode { get; set; }
public string UserID { get; set; }
public string StartDate { get; set; }
public string FinishDate { get; set; }
public string SuccesID { get; set; }
public string Cash { get; set; }
public string ProblemID { get; set; }
public string PageNo { get; set; }
public string DataNo { get; set; }
}
控制器:
[HttpPost]
public IActionResult Search(ProblemsInput problemsinput)
{
return View();
}
【问题讨论】:
标签: jquery json ajax model-view-controller