/*Assuming in a webgrid, someone wants to get a collection of objects that have been checked. MVC3 only returns a single object that has been selected and a count of all rows.
To get a few rows from the webgrid that have been checked, here is a tip on how to do it.
1. Wrap the
div
containing
WebGrid
inside a form to be submited */
@using (Html.BeginForm("Assign","Home"))
{
<div id="grid">
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "webgrid-alternating-row",
columns: grid.Columns(grid.Column(header: "Assign?", format:@<text><input class="check-box" id="assignChkBx"name="assignChkBx" type="checkbox" value="@item.Id"/></text>)))
</div>
<p><input type ="submit" value ="Assign" /></p>
}
[HttpPost]
public ActionResult Assign(FormCollection form)
{
var chckedValues = form.GetValues("assignChkBx");
foreach (var id in chckedValues)
{
}
return RedirectToAction("index");
}