我想将自定义Json对象发布到ASP.NET MVC控制器,但无法正常工作。将json对象发布到ASP MVC无法正常工作
我的JS代码是:
var myData = {
"Message": "Another message",
"Value": 4,
"FirstItem": {
"ItemName": "Este es el primer Item"
},
"SecondItem": {
"ItemName": "Este es el segundo Item"
}
};
$('.clickeable').click(function() {
$.ajax({
type: 'POST',
dataType: 'json',
data: myData,
url: '@Url.Action("PostSomething")',
success: function() {
console.info('Success');
},
error: function() {
console.info('Error');
}
});
});
在我的控制器:
[HttpPost]
public JsonResult PostSomething(SimpleModel model)
{
return Json(true);
}
public class SimpleModel
{
public string Message { get; set; }
public int Value { get; set; }
public SimpleItem FirstItem { get; set; }
public SimpleItem SecondItem { get; set; }
}
public class SimpleItem
{
public string ItemName { get; set; }
//more depth,
}
当得到HttpPost属性和与firstItem SecondItem始终是零。
在此先感谢。