我正在尝试将javascript对象发送到VS 2010中的MVC方法。使用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); } });