在asp.net中将大量数据从视图发送到控制器 [英] Sending large amount of data from view to controller in asp.net
问题描述
更具体地说,让我解释一下我遇到了什么.我试图从视图向控制器提交数据列表.我能够成功提交一些数据,而没有任何问题.但是,当数据超过250个项目列表并且更多时,就会出现问题.当我单击一个提交按钮时,在调试它时它将传递一个NULL值.我的代码没有错误,因为我已经毫无问题地向控制器提交了100个项目的列表.我想我必须指定一些内容,以便它也可以发送大量列表.在这里,我没有使用Ajax或任何JavaScript代码来提交表单.我正在使用发布请求将其直接提交给控制器.
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.
查看
<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>
控制器
[AuthorizedAction]
[HttpPost]
public async Task<IActionResult> SubmitList(List<Student> students)
{
////
}
请告诉我我的代码有什么问题
Can you tell me what's wrong with my code, please
推荐答案
请在Startup#ConfigureServices
Please try this in Startup#ConfigureServices
services.Configure<FormOptions>(options => options.ValueCountLimit = 1000); // you may want to adjust this limit
参考: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.features.formoptions
这篇关于在asp.net中将大量数据从视图发送到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!