【发布时间】:2016-03-18 00:10:49
【问题描述】:
我有一个 MVC 控制器,它以某种方式将 Null 传递给它
控制器:
[HttpPost]
public ActionResult UpdateAllNodes(IEnumerable<ReportGroup> reportGroups)
{
// this is custom return..
return JsonCamel(null);
}
问题:reportGroups 为 null
javascript ajax 帖子
$.post(updateAllNodeUri, JSON.stringify({ reportGroups: homogeneous.data() }));
Chrome 开发工具表单数据:
{"reportGroups":[
{"Id":1,"ReportGroupName":"Standard Reports","ReportGroupNameResID":null,"SortOrder":1,"items":[],"index":0},
{"Id":2,"ReportGroupName":"Custom Reports","ReportGroupNameResID":null,"SortOrder":2,"items":[],"index":1},
{"Id":3,"ReportGroupName":"Retail Reports","ReportGroupNameResID":null,"SortOrder":3,"items":[],"index":2},
{"Id":4,"ReportGroupName":"Admin Reports","ReportGroupNameResID":null,"SortOrder":5,"items":[],"index":3},
{"Id":5,"ReportGroupName":"QA Reports","ReportGroupNameResID":null,"SortOrder":4,"items":[],"index":4},
{"ReportGroupName":"Node","index":5}
]}:
所以我在控制器中有 reportGroups 以及 JSON 作为 reportGroups:因此我不知道为什么它为空。
这里还有 ReportGroup
的 poco 类public class ReportGroup : BaseEntity
{
public override int Id { get; set; }
public string ReportGroupName { get; set; }
public int? ReportGroupNameResID { get; set; }
public int SortOrder { get; set; }
}
剑道数据调用,然后我可以输出到控制台并查看数据
console.log(homogeneous.data());
// ### Send the Data to the server
var updateAllNodeUri = "/Report/UpdateAllNodes";
【问题讨论】:
-
顺便说一句,这是使用 Kendo UI,因此您会看到它添加了一些东西:项目和索引。这些不在我的 poco 课上,但这有关系吗?
-
如果你对数据进行字符串化,你还需要设置
contentType: 'json'选项——尝试使用$.ajax()方法来包含这个选项。
标签: javascript c# json asp.net-mvc asp.net-mvc-routing