I'm trying to send all the CheckBox from my View, however, I can only send the ones that are selected via FormCollection
Controller
public ActionResult Index()
{
List<ListaCheckBox> listacheck = new List<ListaCheckBox>();
Random rand = new Random();
for (int i = 0; i < 4; i++)
{
ListaCheckBox listaDemo = new ListaCheckBox
{
CD_CHECKBOX = i,
CD_SELECIONADO = rand.Next(0,1),
DS_CHECKBOX = "CHECK" + i
};
listacheck.Add(listaDemo);
}
return View(listacheck);
}
[HttpPost]
public ActionResult Index(FormCollection form,ListaCheckBox listaDemo)
{
string[] formCollec = form["chek"].Split(',');
return View();
}
Model
public class ListaCheckBox
{
public int CD_CHECKBOX { get; set; }
public string DS_CHECKBOX { get; set; }
public int CD_SELECIONADO { get; set; }
}
View
@model List<Testes.Models.ListaCheckBox>
@using (Html.BeginForm())
{
@foreach (var item in @Model)
{
<label for="chek">@item.DS_CHECKBOX.ToString()</label>
<input type="checkbox" name="chek" id="check" value="@item.CD_CHECKBOX" />
<br />
}
<br />
<input type="submit" value="Envia CheckBox" />
}
My FormColletion
is receiving, but only the items that have been selected. I wish the unselected would come, too. What am I doing wrong?