Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax Request returns HTTP error 500, using MVC and $.ajax call with POST?

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.

like image 225
SventoryMang Avatar asked Dec 18 '12 22:12

SventoryMang


2 Answers

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.

like image 193
SventoryMang Avatar answered Sep 21 '22 17:09

SventoryMang


Old post, alternative answer ... Just in case someone ends up here ..

My issue was caused by the fact that my controller action that I was calling returned a Partial View Action Result and the PartialView .cshtml file was not being published onto the server (wasnt "included" in the Visual Studio project when publishing).

like image 26
Chris Hammond Avatar answered Sep 18 '22 17:09

Chris Hammond