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 HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
What causes a 500 Internal Server error. This error means there is a problem on the server side. A server error can be caused by any number of things from uploading the incorrect file to as bug in a piece of code. This error response is a generic "catch-all" response.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With