1
Well, I’m facing the following problem in a project I’m working on: how to pass a list (List) with approx. 500~1000 View lines for the Controller?
Actually, this list of mine has a field called "Selected (bool)" from which the user selects only the lines he wants to generate an action, which gives around 50, 100, or even sometimes all of them.
I’m building this into a table and performing a "for" to popular it. The response time to build the View is excellent, but to send the list to my controller and start validating the selected lines and then write to the database, it is absurdly slow/stuck. My controller is receiving the List as a parameter and performing the actions after receipt.
My Controller:
public ActionResult Create(List<MyClass> list) {
foreach (var item in list) {
if (item.Checked) {
// realiza ações
}
}
}
My View:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@* Aqui fica todo o cabeçalho (th) e componentes HTML *@
@for (int r = 0; r < Model.Count(); r++)
{
<tr class="tr-clickable">
@Html.HiddenFor(i => i[r].ID_Usuario)
<td>@Html.CheckBoxFor(i => i[r].Checked)</td>
<td>@Html.DisplayFor(i => i[r].Matricula)</td>
<td>@Html.DisplayFor(i => i[r].Nome)</td>
<td>@Html.DisplayFor(i => i[r].Value)</td>
</tr>
}
@* Aqui ficam os componentes HTML restantes *@
<div class="control-group margin-top-20 pull-right">
<div class="controls">
<input type="submit" class="btn btn-default" value="Gerar" />
</div>
</div>
}
Is there any smarter way to make that "pass"?
I thought of doing via ajax-jQuery, passing line-by-line and recording one-by-one. It works. However, the user has to have the power to give Submit only when he is sure of the selected lines...
Post as your controller.
– Randrade
@Randrade edited!
– Antônio Filho
I believe that the Model Binder was not made to work with so many records in a single request. I think it would be better if you simplify the modeling, making the Action receive a dictionary.
– Leonel Sanches da Silva
@Ciganomorrisonmendez Dictionary? I don’t think I understand it very well... An object like "Dictionary"? ^~
– Antônio Filho
@Antoniofilho That’s right. Can you please put your View in the question?
– Leonel Sanches da Silva
@Gypsy omorrisonmendez Edited!
– Antônio Filho