我试图将json数据传递给。net mvc控制器。似乎mvc自动转换id和lastdatetime正确格式,但不是int[] currentIds,有人知道为什么吗?
var jsonData = {
"id": id,
"lastDataTime": lastDateTime,
"currentIds": [1, 2, 3, 4]
};
public void Process(int id, DateTime lastDateTime, int[] currentIds)
{
}
请试试:
$.ajax({
type: "POST",
url:"@Url.Action("Index", "Home")" ,
data: {
"id": id,
"lastDataTime": lastDateTime,
"currentIds": [1, 2, 3, 4]
},
dataType: "json",
traditional: true,
success: function(msg){
alert(msg)
}
});
public ActionResult Index(int id, DateTime lastDateTime, int[] currentIds)
{
}
简化这个问题并首先使数组工作,试试这个:
<<p> 视图/strong>var myArray = ["1", "2", "3","4"];
$.ajax(
{
type: "POST",
url: '/ControllerName/ActionMethod/',
data: JSON.stringify(myArray),
cache: false,
//dataType: "html",
success: ///
})
控制器public ActionResult Index(List<String> currentIds)
{
///
}
调试并检查列表是否填充,然后引入其他对象。