当前位置: 代码迷 >> ASP.NET >> MVC3的AJAX请求为何返回集合的长度是1,求解!
  详细解决方案

MVC3的AJAX请求为何返回集合的长度是1,求解!

热度:6795   发布时间:2013-02-25 00:00:00.0
MVC3的AJAX请求为什么返回集合的长度是1,求解!!!!!!
前台这样写的
  $.ajax({
  type: 'Post',
  url: '@Url.Action("GetJSON", "Article")',
  dataType: "json",
  success: function (data) {
  alert(data.length);
  $.each(data, function (i, item) {
  alert(item["CatalogId"]);
  });
  }
  });

后台这样
[HttpPost]
  public ActionResult GetJSON()
  {
  return this.Json(new Catalog().GetAllContents());//GetAllContents返回的是一个集合
  }


我这样写的返回对不对?怎么打印 alert(data.length);这个是1,GetAllContents()里面返回的是长度为24个集合
这样传过去,就变成1了,需要怎么修改

------解决方案--------------------------------------------------------
1 应该是1个object吧
------解决方案--------------------------------------------------------
后台这样
[HttpPost]
public JsonResult GetJSON()
{
return this.Json(new Catalog().GetAllContents());//GetAllContents返回的是一个集合
}
  相关解决方案