public JsonResult Get(){ DBEntities db = new DBEntities(); var result = db.GetMenuMaster(); //Convert result to Json}我们需要将我们从数据库中得到的结果集转换为 json,然后才能在 javascript 和 Angularjs 中使用。
3 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
public JsonResult Get()
{
DBEntities db = new DBEntities();
var result = db.GetMenuMaster();
return new JsonResult() { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
慕桂英3389331
TA贡献2036条经验 获得超8个赞
使用也可以试试这个:-
return Json(new { result }, JsonRequestBehavior.AllowGet);
陪伴而非守候
TA贡献1757条经验 获得超8个赞
优化:
[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
};
}
- 3 回答
- 0 关注
- 335 浏览
添加回答
举报
0/150
提交
取消