I've seen several threads about this, and I've tried all the answers (ASP.NET MVC JsonResult return 500)
My ajax request is re-turning a 500 Internal Error. If I debug I never even get to my action.
Here is my ajax call:
$.ajax({
url: '@Url.Action("UpdateSortOrder", "FormItems")',
data: { itemToUpdateId: item.attr("id"), newParentItemId: parentItemId, newPreviousItemId: previousItemId },
type: 'POST',
success: function (data) {
console.log(data);
},
error: function (xhr, status, exception) {
console.log("Error: " + exception + ", Status: " + status);
}
});
And my action:
[HttpPost]
public ActionResult UpdateSortOrder(Guid itemToUpdateId, Guid newParentItemId, Guid newPreviousItemId)
{
FormItem updatedItem = _formItemService.GetOne(x => x.Id == itemToUpdateId);
return Json(updatedItem, JsonRequestBehavior.DenyGet);
}
Using chrome console, these are the response headers from the reply:
HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNetMvc-Version: 3.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Tue, 18 Dec 2012 21:53:41 GMT Content-Length: 17041
Server logs show no substatus codes. Any idea what I am doing wrong here? I've prefer to use POST instead of GET.
The Form Data is being shown as :
itemToUpdateId:18ac5399-342e-4a39-9da1-3281a89501df
newParentItemId:null
newPreviousItemId:null
Which is correct.
I've tried setting the contentType to application/json and traditional = true like in this question: Sending ajax post to mvc with "application/json; charset=utf-8" returns error 500 from vs web developer server
Same error.
Well I was able to figure out what the problem was, there was nothing wrong with my AJAX syntax, or even the action. It was just that my returned object contained a circular reference. I was able to see the actual error in chrome console by clicking on the POST request under Network tab, then viewing the preview tab. This displayed the actual error message.