1

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

Abdulhakim Zeinu
  • 3,333
  • 1
  • 30
  • 37
  • Can you inspect Modelstate because it may give you an indication of what went wrong with the binding – Bob Vale Dec 12 '20 at 19:20
  • check the maximum content length settings https://stackoverflow.com/questions/3853767/maximum-request-length-exceeded – coder_b Dec 12 '20 at 19:25
  • I think it would be better if started using paging. You would only send the amount of rows your page can handle. – Paul Sinnema Dec 12 '20 at 19:48
  • @BobVale I've checked it. There is no problem with binding. If there was It shouldn't have worked for some – Abdulhakim Zeinu Dec 12 '20 at 20:00
  • @coder_b I don't think that Maximum content length is a problem because on the same program I can upload an 80MB file. Since 500 LIST data is much less than even 1MB file I don't think it was a problem – Abdulhakim Zeinu Dec 12 '20 at 20:04
  • 1
    Not sure what the .NET Core equivalents are, but ASP.NET (on IIS) has always had a maximum request size limit, and a "maximum fields" limit (can't remember what it's actually called, but it deals with how many form values are in a given request). Are you only sending the row ID (that's the only hidden field in your example)? – Tieson T. Dec 12 '20 at 20:47
  • No, I've totally 3 hidden fields including the row Id and another 2 hidden fields – Abdulhakim Zeinu Dec 12 '20 at 20:54
  • So, three hidden fields per row? – Tieson T. Dec 12 '20 at 20:55
  • Yes, I have three hidden fields per row. – Abdulhakim Zeinu Dec 12 '20 at 21:00
  • 1
    Assuming you're running on IIS, you are probably hitting the limit described here: https://stackoverflow.com/questions/8684049/asp-net-ms11-100-how-can-i-change-the-limit-on-the-maximum-number-of-posted-for - IIS has a default maximum of 500 form fields per request, and your 250 rows would be submitting 750. – Tieson T. Dec 12 '20 at 21:05
  • Yes, You are right. That is the problem behind it. am using IIS server. I've gone through the link you've posted above. I understood the reason. I think the solution to the above question will be applied on asp.net 4.0 and below. mine is ASP.NET CORE(5.0). It is not working on my version. But when I apply the answer from Roar S. It is working. Thank You for helping. – Abdulhakim Zeinu Dec 13 '20 at 08:42

1 Answers1

5

Please try this in Startup#ConfigureServices

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

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

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
Roar S.
  • 8,103
  • 1
  • 15
  • 37