I have an mvc application in which I am using a model like this:
public class BlockedIPViewModel
{
public string IP { get; set; }
public int ID { get; set; }
public bool Checked { get; set; }
}
Now I have a View to bind a list like this:
@model IEnumerable<OnlineLotto.Web.Models.BlockedIPViewModel>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
}
@foreach (var item in Model) {
<tr>
<td>
@Html.HiddenFor(x => item.IP)
@Html.CheckBoxFor(x => item.Checked)
</td>
<td>
@Html.DisplayFor(modelItem => item.IP)
</td>
</tr>
}
<div>
<input type="submit" value="Unblock IPs" />
</div>
Now I have a controller to receive action from submit button:
public ActionResult BlockedIPList(IEnumerable<BlockedIPViewModel> lstBlockedIPs)
{
}
But I am getting null value to lstBlockedIPs when coming to controller action.I need to get the checkbox state here. Please help.