我有一个3实体的观点。 当我点击提交按钮时,我想保存这些实体。我想一次保存3个实体条目。如何做到这一点
在视图
<div class="editor-field ">
<%: Html.TextBoxFor(model => model.ElementAt(0).UserQuestion1)%>
<%: Html.ValidationMessageFor(model => model.ElementAt(0).UserQuestion1)%>
</div>
<div class="editor-field ">
<%: Html.TextBoxFor(model => model.ElementAt(0).UserAnswer)%>
<%: Html.ValidationMessageFor(model => model.ElementAt(0).UserAnswer)%>
</div>
<div class="editor-field ">
<%: Html.TextBoxFor(model => model.ElementAt(1).UserQuestion1)%>
<%: Html.ValidationMessageFor(model => model.ElementAt(1).UserQuestion1)%>
</div>
<div class="editor-field ">
<%: Html.TextBoxFor(model => model.ElementAt(1).UserAnswer)%>
<%: Html.ValidationMessageFor(model => model.ElementAt(1).UserAnswer)%>
</div>
<div class="editor-field ">
<%: Html.TextBoxFor(model => model.ElementAt(2).UserQuestion1)%>
<%: Html.ValidationMessageFor(model => model.ElementAt(2).UserQuestion1)%>
</div>
<div class="editor-field ">
<%: Html.TextBoxFor(model => model.ElementAt(2).UserAnswer)%>
<%: Html.ValidationMessageFor(model => model.ElementAt(2).UserAnswer)%>
</div>
在控制器
public ActionResult ChooseQuestion()
{
List<UserQuestion> lst = new List<UserQuestion>() {
new UserQuestion(),new UserQuestion(), new UserQuestion()
};
return View(lst);
}
[HttpPost]
public void ChooseQuestion(List<UserQuestion> lst)
{
//lst is always NULL Why
//EntityFactory.GetEntity().SaveChanges();
}
为什么当我点击提交按钮,我的参数列表LST为null。 我想进行保存。
谢谢。
这是我所需要的。谢谢。 – 2010-11-03 15:19:51