1

I am using ASP.NET MVC5 and passing a list of objects to an action via ajax. Ideally, I want to pass around 10K items in the list but for some reason, I can not pass more than 65 items. Every time i try to pass more than 65, I get 500 internal server error. I tried debugging with breakpoints but it seems like the call never even hits my action. The action code is:

 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 });
    }

And my Ajax call is:

            $('#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";
                });
        });
hkjhadj1
  • 848
  • 3
  • 13
  • 32

1 Answers1

1

Try 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>
Adrian Brand
  • 20,384
  • 4
  • 39
  • 60