Sunday, 8 September 2013

IEnumerable View returning null on HttpPost

IEnumerable View returning null on HttpPost

I have a Form which is filled with some grid like structure with
CheckBoxes and DisplayField. I want to fetch rows with Checked CheckBoxes.
Problem is i am getting null in Controller's post method.
My models is
public class RegisterModuleSelection
{
[Display(Name = "ID")]
public int mID { get; set; }
[Display(Name = "Module")]
public string Module { get; set; }
[Display(Name = "Buy")]
public bool Buy { get; set; }
}
View
@model IEnumerable<MAK_ERP.Models.RegisterModuleSelection>
@{
ViewBag.Title = "Register - Modules Selection";}
<h2>
Register - Modules Selection</h2>
@using (Html.BeginForm("RegisterModules", "UserAccount", FormMethod.Post,
new { id = "RegisterModules", @class = "generalForm" }))
{
<table class="Grid Module">
<tr>
<th>
@Html.DisplayNameFor(model => model.Module)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
<th>
@Html.DisplayNameFor(model => model.Duration) (Months)
</th>
<th>
@Html.DisplayNameFor(model => model.Buy)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.HiddenFor(modelItem => item.mID)
@Html.DisplayFor(modelItem => item.Module)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.EditorFor(modelItem => item.Duration)
</td>
<td>
@Html.CheckBoxFor(modelItem => item.Buy)
</td>
</tr>
}
<tr>
<td colspan="4">
<input type="submit" value="Next" class="button3" />
<input type="reset" value="Reset" class="button4" />
</td>
</tr>
</table>
}
Controller
[HttpGet]
public ActionResult RegisterModules()
{
IEnumerable<MAK_ERP.Models.RegisterModuleSelection> model =
reg.getModules();
return View(model);
}
[HttpPost]
public ActionResult
RegisterModules(IEnumerable<Models.RegisterModuleSelection> regMod)
{
...

No comments:

Post a Comment