Example:
Model:
public class Exemplo
{
public int Id { get; set; }
public string Nome { get; set; }
}
Controller and View:
public ActionResult Index()
{
IList<Exemplo> exemplos = new List<Exemplo>();
exemplos.Add(new Exemplo {Id = 1, Nome = "Nome 1"});
exemplos.Add(new Exemplo { Id = 2, Nome = "Nome 2" });
return View(exemplos);
}
@{ ViewBag.Title = "Index"; }
@using (Html.BeginForm("Resgatar", "Exemplo", FormMethod.Post))
{
<table class="table">
<tr>
<td>
@Html.Display("Selecionar")
</td>
<th>
@Html.DisplayNameFor(model => model.Nome)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<input type="checkbox" name="Ids" value="@item.Id" />
</td>
<td>
@Html.DisplayFor(modelItem => item.Nome)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
<tr>
<td colspan="4">
<button type="submit" class="btn btn-primary">Alterar</button>
</td>
</tr>
</table>
}
Controller with Actionresult of selected Id:
[HttpPost]
public ActionResult Resgatar(IEnumerable<int> Ids)
{
return View();
}
This way you will receive a list of Id of all those selected. Redo the search in your database and change the required data.
The question that remains is
chekbox´s
, are several ? Your model is like, put your full code ?– user46523