MVCContrib Grid:
@model ViewModel
@using (Html.BeginForm("SendData", "Home", FormMethod.Post))
{
@Html.Grid(Model.List).Columns(c =>
{
c.For(x => x.Id);
c.For(x => x.Name);
c.For(x =>Html.Partial("Partial/CheckBoxTemplate", new CheckBoxViewModel { Id = x.Id })).Named("Options");
})
@Html.SubmitButton()
}
Controller Post Action:
public ActionResult SendData(List<CheckBoxViewModel> list)
{
return View();
}
ViewModels:
public class CheckBoxViewModel
{
public int Id { get; set; }
public bool CheckBox { get; set; }
}
public class ViewModel
{
public IPagination<Data> List { get; set; }
}
public class Data
{
public int Id { get; set; }
public string Name { get; set; }
}
Partial View:
@model MvcApplication1.Models.CheckBoxViewModel
@Html.HiddenFor(x => x.Id)
@Html.CheckBoxFor(x => x.CheckBox)
All checkboxed are by default not checked.
How can I retrieve all checked checkbox values in my SendData
action?
Partial/CheckBoxTemplate.cshtml
? Also you seem to be binding to someName
property (c.For(x => x.Name);
) but I can't see such property defined in yourCheckBoxViewModel
. Could you please show your real code? – HexaneId
to your partial and you never set the booleanCheckBox
property. Why aren't you using a view model? Why does yourViewModel
uses anIPagination<Data>
property instead ofIPagination<CheckBoxViewModel>
which would have made much more sense since you are attempting to generate checkboxes in your view? – Hexane