[英]Ajax Post return type instead of value c# mvc 4
i have this problem. 我有这个问题。
my function is this 我的功能是这个
$.ajax({
type: "POST",
url: "/controller/CreateList",
contentType: "application/json; charset=utf-8",
traditional: true,
data: JSON.stringify(myvar),
success: function (returnArray) {
}
.....
in my controller i have this action: 在我的控制器中,我有以下操作:
public int[] CreateList(List<ERoleCommission> erolecommission){
List<int> intList= new List<int>();
...//populate the List
return intList.ToArray();
}
with debug i see that intList has filled with the right value, so it isn't ac# error, after calling this action from controller the debug return to js function and returnArray = "System.Int32[]", it contains only type. 通过调试,我看到intList已填充正确的值,因此它不是ac#错误,从控制器调用此操作后,调试返回js函数,并且returnArray =“ System.Int32 []”,它仅包含类型。 why?
为什么? thanks
谢谢
Without seeing your controller/action I only guess, but my first guess would be that you forget to JSON-encode the data before you return it as an ActionResult from your action. 我没有看到您的控制器/动作,但是我的第一个猜测是您忘记了对数据进行JSON编码,然后再将其作为ActionResult从操作中返回。 Try something like this in your action:
在您的操作中尝试以下操作:
public JsonResult YourAction() {
// ... do stuff
var yourArrayOfData = CreateList(yourListOfData);
return Json(yourArrayOfData);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.