我使用下面的代碼:在HTTP POST方法無效獲取響應
控制器:
public ActionResult Update(int studentId = 0, int subjectId = 0)
{
Engine engine = new Engine(studentId, subjectId);
List<Chapter> chapterList = engine.GetChapters();
return View(chapterList);
}
[HttpPost]
public ActionResult Update(List<Chapter> model)
{
return View(model);
}
Update.cshtml:
@model IEnumerable<Chapter>
@{
ViewBag.Title = "Update";
}
<h2>
Update</h2>
@using (Html.BeginForm("Update", "StudyPlan", FormMethod.Post))
{
<fieldset>
<table>
@foreach (var item in Model)
{
<tr>
<td>
@item.name
</td>
<td>
@Html.CheckBoxFor(chapterItem => item.included)
</td>
</tr>
}
</table>
<input type="submit" value="submit" />
</fieldset>
}
我想,當用戶選擇複選框,響應應該出現在控制器的httppost
方法中。但我得到空值更新方法。我是否做錯了
請問你的'chapter'模型? – Zafar