【发布时间】:2017-08-30 23:36:24
【问题描述】:
当页面加载到我的 .NET MVC 应用程序中时,我已经设置了一个 getJSON 调用,如下所示:
$(document).ready(function(){
$.getJSON("/Administrator/GetAllUsers", function (res) {
// getting internal server error here...
});
});
动作看起来像这样:
[HttpGet]
[ActionName("GetAllUsers")]
public string GetAllUsers()
{
return new JavaScriptSerializer().Serialize(ctx.zsp_select_allusers().ToList());
}
我收到此错误:
500 (Internal Server Error)
我在这里做错了什么???
【问题讨论】:
-
return Json(ctx.zsp_select_allusers(), JsonRequestBehavior.AllowGet); -
去掉 Administrator/GetAllUsers 前的斜杠 / 并检查。你的返回类型应该是 JsonReturn
-
并且它需要是
public ActionResult GetAllUsers()或public JsonResult GetAllUsers() -
@BasantaMatia 仍然无法正常工作:/
-
不需要
.ToList()(它正在序列化,因此正在迭代集合)
标签: c# jquery asp.net asp.net-mvc asp.net-mvc-5