Я столкнулся с проблемой, когда мой список пуст, когда я пытался получить данные из моей формы. Это работает в Form Collection, но не когда я пытаюсь вернуться в виде списка.
Контроллер
[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>
}
Модель
public class VerifyVM
{
[Display(Name = "Course Name")]
public string CourseName { get; set; }
public string Cost { get; set; }
public string ErrorMsg { get; set; }
}