为什么JsonResult产生500内部服务器错误? [英] Why does JsonResult produce 500 internal server error?

查看:332
本文介绍了为什么JsonResult产生500内部服务器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找回从我的Microsoft SQL Server数据库的值。这是一个可为空的位。

I am trying to retrieve a value from my Microsoft SQL Server database. It is a nullable "bit".

在code检索

[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"); 
}

而code检索:

And the code to retrieve:

$.getJSON('WishesVisit', function (data) {
    alert(data);
});

为什么我得到一个500内部服务器错误?

Why am i getting a 500 internal server error?

调试器不捕获任何异常。

The debugger doesn't catch any exception.

推荐答案

问题是最有可能的,因为ASP.NET MVC不允许使用GET默认JSON请求。您可以添加 JsonRequestBehavior.AllowGet 作为第二个参数到您的JSON电话:

The problem is most likely because ASP.NET MVC does not allow JSON requests using GET by default. You can add JsonRequestBehavior.AllowGet as a second parameter to your Json call:

return Json("true", JsonRequestBehavior.AllowGet);

如果没有,你可以提供一个错误信息?

If not, can you provide a error message?

这篇关于为什么JsonResult产生500内部服务器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆