当页面加载到我的 .NET MVC 应用程序中时,我已经设置了一个 getJSON 调用,如下所示:
$(document).ready(function(){
$.getJSON("/Administrator/GetAllUsers", function (res) {
// getting internal server error here...
});
});
Action 看起来像这样:
[HttpGet]
[ActionName("GetAllUsers")]
public string GetAllUsers()
{
return new JavaScriptSerializer().Serialize(ctx.zsp_select_allusers().ToList());
}
我收到这个错误:
500 (Internal Server Error)
我在这里做错了什么???
最佳答案
在 MVC 中,仅当您出于某些安全目的向它发出 post
请求时才返回 json 结果,直到并且除非您明确指定 JsonRequestBehavior.AllowGet
,否则也会更改您的返回值类型
[HttpGet]
[ActionName("GetAllUsers")]
public JsonResult GetAllUsers()
{
return Json(ctx.zsp_select_allusers(), JsonRequestBehavior.AllowGet);
}
关于c# - .NET MVC 的 jQuery getJSON 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43229760/