使用“application / json;将ajaxpost发送到mvc; charset = utf-8“从vs web开发人员服务器返回错误500

我试图在VS 2010中向我的MVC方法发送一个javascript对象。使用VS Web服务器。

$.ajax({ type: "POST", url: "@Url.Action("Filter", "Grid")", dataType: "json", data: {"data": JSON.stringify(filtersData) }, contentType: "application/json; charset=utf-8", traditional: true, success: function (data) { alert("ok"); }, error:function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); 

添加contentType参数时会导致500错误。 我究竟做错了什么?

这最终奏效了:

  var filtersApplyData = GetFiltersApplyData@(Model.PropertyID)(); var data = JSON.stringify({data: filtersApplyData, classID: @(Model.ClassID)}); $.ajax({ type: "POST", url: "@Url.Action("ApplyFilters", "Grid")", data: data, contentType: "application/json", traditional: true, success: function (data) { $("#grid").html(data); }, error:function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(ajaxOptions); alert(thrownError); } }); 

你发布的内容很难说清楚。

500错误意味着您调用的服务存在,但error handling您传递给它的数据。

如果您可以控制服务(听起来可能基于问题的标题),请检查其错误日志或直接在服务器上运行代码(通常您会收到更广泛的错误消息)。 如果您没有任何错误记录(例如,没有NLog等),请检查Windows事件日志。

如果您无法控制该服务,请通知提供该服务的人员它正在产生错误。