传递大数据时500内部服务器错误

时间:2018-09-19 22:21:48

标签: asp.net-mvc asp.net-web-api

我正在使用ASP.NET MVC5,并通过ajax将对象列表传递给操作。 理想情况下,我希望通过列表中的1万个项目,但是由于某种原因,我不能传递超过65个项目。每当我尝试通过65以上时,都会收到500个内部服务器错误。我尝试使用断点进行调试,但似乎该调用甚至都没有击中我的动作。动作代码为:

 public ActionResult DownloadExcel(List<DbEntity> list)
    {
        FileDataViewModel fileData = new FileDataViewModel { FileName = "foo", FilePath = "bar" };
        //I want to do something else here but that's not the point of this
        return Json(new { fileData });
    }

我的Ajax电话是:

            $('#btn').click(function () {
            dto = @Html.Raw(Json.Encode(Model));

            console.log(dto);
            //I have checked the console and the array is correct, there is  no problem with the dto variable 
            $.ajax({
                url: "/DbEntities/DownloadExcel",
                contentType: "application/json; charset=utf-8",
                method: "POST",
                data: JSON.stringify(dto),
            })
                .done(function (response) {
                    document.getElementById("mySpan").innerHTML = "<hr>File created successfully<br>";
                })
                .fail(function (response) {
                    document.getElementById("error").innerHTML = "Error creating file";
                });
        });

1 个答案:

答案 0 :(得分:1)

尝试maxJsonLength

<system.web.extensions>
    <scripting>
        <webServices>
            <!-- Try increasing this value to a larger value (Int.MaxValue used below) -->
            <jsonSerialization maxJsonLength="2147483644"></jsonSerialization>
        </webServices>
    </scripting>
</system.web.extensions>