【发布时间】:2014-02-11 12:40:00
【问题描述】:
我正在使用以下代码:
控制器:
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);
}
更新.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模型是什么样的?
标签: c# asp.net-mvc-4