我试图让我的控制器返回一个命名的JSON数组。它目前返回格式如下:
[{"Title":"Star Wars: A New Hope","Year":1977},{"Title":"Star Wars: The Empire Strikes Back","Year":1980},{"Title":"Star Wars: Return of the Jedi","Year":1983}]
但我希望它像这样
movies:[{"Title":"Star Wars: A New Hope","Year":1977},{"Title":"Star Wars: The Empire Strikes Back","Year":1980},{"Title":"Star Wars: Return of the Jedi","Year":1983}]
这是我的控制器方法:
public JsonResult GetMovies()
{
var model = _movies;
return Json(model, JsonRequestBehavior.AllowGet);
}
有什么想法吗?
答案 0 :(得分:3)
您可以返回匿名json对象,如
return Json(new {
movies = model
} , JsonRequestBehavior.AllowGet);