I am trying to retrieve a value from my Microsoft SQL Server database. It is a nullable “bit”.
The code to retrieve
[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");
}
And the code to retrieve:
$.getJSON('WishesVisit', function (data) {
alert(data);
});
Why am i getting a 500 internal server error?
The debugger doesn’t catch any exception.
The problem is most likely because ASP.NET MVC does not allow JSON requests using GET by default. You can add
JsonRequestBehavior.AllowGetas a second parameter to your Json call:If not, can you provide a error message?