小编典典

使用“ application / json;将ajax发布到mvc; charset = utf-8”从Web开发人员服务器返回错误500

ajax

我正在尝试将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错误。我究竟做错了什么?


阅读 230

收藏
2020-07-26

共1个答案

小编典典

最终成功了:

    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); 
            }
    });
2020-07-26