I have this class of Status :
public class Status
{
public Status(int id, string description)
{
Id = id;
Description = description;
}
public int Id { get; set; }
public string Description { get; set; }
public bool IsChecked { get; set; }
}
This is my Model:
public class StatusModel
{
public StatusModel()
{
Statuses = new List<Status>();
}
public List<Status> Statuses { get; set; }
}
and my View looks like this:
@model MVCTestApplication.Models.StatusModel
@using (Html.BeginForm("TestView", "Home"))
{
<table>
<thead>
<tr>
<th>
Status
</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Statuses.Count(); i++)
{
<tr>
<td>
@Html.CheckBoxFor(x => x.Statuses[i].IsChecked, new { @id = Model.Statuses[i].Id })
@Html.LabelFor(x => x.Statuses[i].Description, Model.Statuses[i].Description)
@Html.HiddenFor(x => x.Statuses[i].Description)
@Html.HiddenFor(x => x.Statuses[i].Id)
</td>
</tr>
}
</tbody>
</table>
<input type="submit" name="submit" value="submit" />
}
and in controller I have:
public ActionResult TestView(StatusModel statuses)
{
//.......
}
I need to select all checked checkbox items, but when i wrote such code, I get null for my statuses variable in controller. And I don't know what I did wrong