I have a list object within my Model in which I am trying to bind in my post action. However, the list is always null when I post. Please help on how to correct this. I have the following Model:
My Model vw_FormInfo.cs
public partial class vw_FormInfo
{
...
public List<vw_SectionQuestion> SectionQuestion { get; set; }
}
vw_SectionQuestion.cs
public partial class vw_SectionQuestion
{
...
public int SectionID { get; set; }
public string SectionName { get; set; }
public string SectionDesc { get; set; }
public string Description { get; set; }
...
}
My View Index.cshtml
@model EvalTool.Models.vw_FormInfo
@{
var formSections = Model.SectionQuestion.GroupBy(item => new { item.SectionID, item.SectionName, item.SectionDesc });
};
...
@using (Html.BeginForm("Edit", "FormInfo", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
...
@{int i = 0,j = 0; }
<table id="dataTables-survey" class="compact table table-striped table-bordered table-hover dataTables">
@foreach (var formSection in formSections)
{
<thead>
<tr>
<th></th>
<th>@formSection.Key.SectionID @formSection.Key.SectionName</th>
<th>@formSection.Key.SectionDesc</th>
</tr>
</thead>
<tbody>
@foreach (var question in formSection)
{
<tr class="sect-quest-@i">
<td>@Html.EditorFor(modelItem => modelItem.SectionQuestion.ElementAt(j).Description)</td>
<td>@question.Order</td>
<td>@question.Description</td>
</tr>
j++;
}
</tbody>
i++;
}
<tfoot>
<tr>
<td></td>
<td></td>
<td><input type="submit" class="btn btn-primary" value="Edit" /></td>
</tr>
</tfoot>
</table>
} @*End Form*@
My Controller FormInfoController.cs
public class FormInfoController : Controller
{
...
[HttpPost]
public ActionResult Edit([Bind(Include= "SectionQuestion")] vw_FormInfo vw_forminfo)
{
var s = vw_forminfo;
var sections = vw_forminfo.SectionQuestion; // This is ALWAYS null
return View(vw_forminfo);
}
...
}