【发布时间】:2015-01-02 20:51:15
【问题描述】:
我正在尝试将 JSON 数组发送到 ASP MVC 控制器。我首先尝试了一个 JSON 对象,它确实有效,但在我尝试数组 JSON 对象时失败了。正如下面的代码所示,我希望得到 ListForm2 为,
ListForm2[0].MarketID = 1, ......
ListForm2[1].MarketID = 2, ......
但是,我得到了 ListForm2=null。我的编码有什么问题?
function ProcessSaveView(area, bChecked, bChart, saveName) {
var jsondata = [{ MarketID: 1, ForecastPointTypeID: 5, ForecastPointID: 21, CustomTimeZoneID: "ET-Prevailing", IsChart: true },
{ MarketID: 2, ForecastPointTypeID: 5, ForecastPointID: 51, CustomTimeZoneID: "ET-Prevailing", IsChart: true }];
$.ajax({
type: "POST",
url: "./charts/SaveViewToDatabase",
dataType: "json",
traditional: true,
data: jsondata,
success: function (result) {
if (result.success) {
alert("Save View successful!");
} else {
alert("Duplicate View already exist. Not save!");
}
},
error: function () {
alert("No market, load type & region is selected!");
}
});
}
[HttpPost]
public ActionResult SaveViewToDatabase(testJsonObject[] ListForm2)
{
return Json(new { success = true });
}
public class testJsonObject
{
public int ForecastPointID { get; set; }
public int MarketID { get; set; }
public int ForecastPointTypeID { get; set; }
public string CustomTimeZoneID { get; set; }
public bool IsChart { get; set; }
}
【问题讨论】:
-
验证你的 json 结构可能是错误
-
更改 ListForm2={all values} 的名称 jsondata 显示此论坛 ..stackoverflow.com/questions/7116099/…
标签: c# asp.net asp.net-mvc json asp.net-mvc-4