In ASP MVC I have a controller that returns json data:
public JsonResult Edit(int? id)
{
if(id==null)
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(new { message = "Bad Request" }, JsonRequestBehavior.AllowGet);
}
car carTmp = db.car.Find(id);
if (carTmp == null)
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return Json(new { message = "Not Found" }, JsonRequestBehavior.AllowGet);
}
return Json(carTmp, JsonRequestBehavior.AllowGet);
}
I also have the following ajax request:
$.getJSON("Edit/" + data, function (result) {
var car = result;
})
.error(function (error) {
alert(error.message);
})
Why, in case of success, in the result object I have the json object (i.e: I can access result.id, result.name ecc...) but in case of error, error.message is undefined? (I have the message into error.responseJson.message)