前台这样写的
$.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了,需要怎么修改
$.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了,需要怎么修改
alert(item.CatalogId);
});
[HttpPost]
public JsonResult GetJSON()
{
return this.Json(new Catalog().GetAllContents());//GetAllContents返回的是一个集合
}
就是一个对象集合么,比如说 一个User类 属性name
List<User> list=new List<User>();
list.Add(n个User对象)..
集合 return list;