Sending large amount of data from view to controller in asp.net

浪子不回头ぞ 提交于 2021-01-29 09:05:41

问题


To be more specific let me explain what did I encounter. I was trying to submit a List of data from view to controller. I was able to submit some data successfully without any problem. But the problem arises when the data is more than around a list of 250 items and more than that. When I click a submit button it passes a NULL value when I debug it. There is no error with my code because I have submitted a list of 100 items to the controller without any problem. I guess there will be something that I have to specify so that It will also send a large number of lists. Here I'm not using ajax or any javascript code to submit the form. I'm submitting it directly to the controller using post request.

I have posted some snippet of my code below to describe it more precisely.

View

    <form method="post" action="SubmitList">
                <div class="row"> 
                    <div class="col-md-12" style="padding-top:1%">
<input type="submit" value="PASS" class="btn btn-primary" style="float:right;" />
                        <div class="box-body">
                            <table id="#example1" class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>Name</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @{
                                        int i = 1;
                                    }
                                    @for (int j = 0; j < Model.Count(); j++)
                                    {
                                        <tr>
                                            <td>@Html.Raw(i++)</td>
                                            @Html.HiddenFor(item => item[j].Id, new { htmlAttributes = new { @class = "form-control" } })
                                            <td>
                                                @Html.DisplayFor(item => item[j].FullName) 
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                                <tfoot>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </form>

Controller

[AuthorizedAction]
[HttpPost] 
public async Task<IActionResult> SubmitList(List<Student> students)
    {
////
    }

Can you tell me what's wrong with my code, please


回答1:


Please try this in Startup#ConfigureServices

services.Configure<FormOptions>(options => options.ValueCountLimit = 1000); // you may want to adjust this limit

Reference: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.features.formoptions



来源:https://stackoverflow.com/questions/65268873/sending-large-amount-of-data-from-view-to-controller-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!