public JsonResult Get()
{
DBEntities db = new DBEntities();
var result = db.GetMenuMaster();
//Convert result to Json
}
我们需要将从数据库中获得的结果集转换为json,然后才能在javascript和Angularjs中使用它。
答案 0 :(得分:2)
使用也可以尝试:-
return Json(new { result }, JsonRequestBehavior.AllowGet);
答案 1 :(得分:1)
public JsonResult Get()
{
DBEntities db = new DBEntities();
var result = db.GetMenuMaster();
return new JsonResult() { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
答案 2 :(得分:0)
优化:
[HttpGet]
public ActionResult Get()
{
DBEntities db = new DBEntities();
var result = db.GetMenuMaster();
return new JsonResult
{
Data = result,
ContentEncoding = Encoding.UTF8,
ContentType = "application/json",
MaxJsonLength = int.MaxValue,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}