我看过几个关于这个问题的帖子,也尝试了所有答案 (ASP.NET MVC JsonResult return 500)
我的ajax请求返回500内部错误。如果我进行调试,甚至无法进入我的操作。
这是我的ajax调用:
$.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);
}
});
我的行动:
[HttpPost]
public ActionResult UpdateSortOrder(Guid itemToUpdateId, Guid newParentItemId, Guid newPreviousItemId)
{
FormItem updatedItem = _formItemService.GetOne(x => x.Id == itemToUpdateId);
return Json(updatedItem, JsonRequestBehavior.DenyGet);
}
使用Chrome控制台,以下是响应的响应标头:
HTTP/1.1 500 内部服务器错误 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
服务器日志没有显示任何子状态代码。您知道我在这里做错了什么吗?我更喜欢使用POST而不是GET。
表单数据显示为:
itemToUpdateId: 18ac5399-342e-4a39-9da1-3281a89501df
newParentItemId:null
newPreviousItemId:null
这是正确的。
我尝试设置contentType为application/json并且traditional=true,就像在此问题中一样:Sending ajax post to mvc with "application/json; charset=utf-8" returns error 500 from vs web developer server
同样的错误。