You might want to look at a custom ModelBinder.
I am using the grid and I have a checkbox column that looks like this:
column.For(x => Html.CheckBox(x.CatalogItemId + "-rcvd", false)).DoNotEncode().Named("Received");
My action signature in the controller to handle post back is this:
[HttpPost]
public virtual ActionResult Index([ModelBinder(typeof(PendingRecievedItemsBinder))]IEnumerable<ShelfMyndr.Models.Previews.PendingReceivedCatalogItem> rcvdCatalogItems)
You just need a class that implements IModelBinder
. In the BindModel
method you can do something like this:
foreach (string key in controllerContext.HttpContext.Request.Form.AllKeys.Where(k => controllerContext.HttpContext.Request[k].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Length > 1))
{
if (key.EndsWith("-rcvd"))
{
ci.IsReceived = true;
}
Using this, my controller's action can focus on what do do with a list of items, instead of iterating thru the Forms collection itself.