I'm running into a problem where my List is null when I tried to retrieve data from my form. It works in Form Collection, but not when I try to return as a list.
Controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Verify(List<VerifyVM> VC)
{
return View();
}
View
@model IEnumerable<Appliecation.Models.ViewModel.VerifyVM>
using (Html.BeginForm("Verify", "Sections", FormMethod.Post))
{
@Html.AntiForgeryToken()
<table class="table table-striped">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.CourseName)</th>
<th>@Html.DisplayNameFor(model => model.Cost)</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(model => item.CourseName, new { @class = "form-control" })@Html.HiddenFor(model => item.CourseName)
</td>
<td>
@Html.DisplayFor(model => item.Cost, new { @class = "form-control" })@Html.HiddenFor(model => item.Cost)
</td>
</tr>
}
</tbody>
</table>
<div class="text-right">
<button type="button" id="goback" class="btn">Back</button>
<input type="submit" id="submit" value="Submit" class="btn" />
</div>
}
Model
public class VerifyVM
{
[Display(Name = "Course Name")]
public string CourseName { get; set; }
public string Cost { get; set; }
public string ErrorMsg { get; set; }
}