3
I am working on a project of which I own a page that lists some records, of which I will 'flirt' some to perform batch actions such as deletion, status change, among others.
How do I send this list of mine with the 'fledged' records to different actions?
My list is built like this:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<table>
<tr>
<th>Selecione</th>
<th>Descrição</th>
</tr>
@for (int r = 0; r < Model.Count(); r++)
{
<tr>
<td>@Html.CheckBoxFor(i => i[r].Selecionado)</td>
<td>@Html.DisplayFor(i => i[r].Descricao)</td>
</tr>
}
</table>
<input type="button" value="Alterar Selecionados Para Status x" />
<input type="button" value="Alterar Selecionados Para Status y" />
<input type="button" value="Alterar Selecionados Para Status z" />
}
In my post method, I receive the parameter as follows:
[...]
public ActionResult SelectLines(List<Objeto> list) { [...] }
Through Ajax. You’ve managed to generate this list so I can direct it as code?
– Leonel Sanches da Silva
Yes, I have an 'Index' action that has a list of objects with a Boolean field called 'selected'. If I do a single Ubmit, I can pass this list to my action by the POST method without any problems. But in cases of more than one action, I don’t know how to do it... How would I send the list via ajax for a specific action? via: date: $('table'). serialize() ?
– Antônio Filho
Then, clicking the field would trigger Ajax. You can put in your question an example in code?
– Leonel Sanches da Silva
The big challenge would be for Ajax to know where to send the information. How is a Action different per line, there would have to be a way to jot down the information that led to the Action somewhere in the HTML.
– Leonel Sanches da Silva
If you want to act the same action in each thing that is sealed, it is much simpler. So you can click on as many checkboxes as you want, and click Submit only once. I would use the same Model you used to generate the list in your View. From there just turn the selected items into a JSON array
– brazilianldsjaguar
Putz... I confess that I was a bit confused... I edited my question, to try to further detail my difficulty. I can usually send the list to an action present in a form. In this action I see the list in search of the 'selected' items to start treating them.
– Antônio Filho