Ken*_*nci 6 asp.net-mvc asp.net-mvc-3
我试图从我的Microsoft SQL Server数据库中检索一个值.它是一个可以为空的"位".
要检索的代码
[HttpGet]
public JsonResult WishesVisit()
{
int firmaid = SessionExtensions.GetFirmaId(Session);
var firma = db.Firma.Where(x => x.firma_id == firmaid).FirstOrDefault();
if (firma != null)
{
if (firma.oensker_besog != null)
{
if ((bool)firma.oensker_besog)
{
return Json("true");
}
else
{
return Json("false");
}
}
}
return Json("null");
}
Run Code Online (Sandbox Code Playgroud)
并检索代码:
$.getJSON('WishesVisit', function (data) {
alert(data);
});
Run Code Online (Sandbox Code Playgroud)
为什么我会收到500内部服务器错误?
调试器不会捕获任何异常.
ale*_*exn 17
问题很可能是因为ASP.NET MVC默认情况下不允许使用GET的JSON请求.您可以将JsonRequestBehavior.AllowGet第二个参数添加到Json调用:
return Json("true", JsonRequestBehavior.AllowGet);
Run Code Online (Sandbox Code Playgroud)
如果没有,你能提供错误信息吗?
| 归档时间: |
|
| 查看次数: |
5456 次 |
| 最近记录: |