Well, I'm facing the following problem in a project I'm working on: how to pass a list (List) with approx. 500 ~ 1000 lines from the View to the Controller?
In fact, this list has a field called "Selected (bool)" from which the user selects only the rows he wants to generate an action, which is around 50, 100, or sometimes all of them .
I'm building this on a 'table' and performing a 'for' to popular the same. The response time to build the View is excellent, but to send the list to my controller and start validating the selected rows and later write to the database is absurdly slow / slow. My controller is getting the List as parameter and performing the actions upon 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 do this "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 only submit when he is sure of the selected rows ...