【发布时间】:2011-03-21 18:59:04
【问题描述】:
我可以从我的 ActionResult 调用 JsonResult 方法吗?我想要做的是在我的 MVC.Site 项目中有一个区域来专门处理 API(只需返回 json 以便我可以重用非 mvc 项目)。然后从不同的 ActionResult(我处理数据和视图),我想调用 JsonResult,然后返回该 Json 数据以及视图信息。即:
public JsonResult GetSongs()
{
var songs = _music.GetSongs(0, 3);
return Json(new { songs = songs }, JsonRequestBehavior.AllowGet);
}
public ActionResult Songs()
{
// Get the data by calling the JsonResult method
var data = GetSongs();
return Json(new
{
// Render the partial view + data as json
PartialViewHtml = RenderPartialViewToString("MyView", data),
success = true
});
}
谢谢。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3