【发布时间】:2010-11-02 10:14:23
【问题描述】:
我有 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();
}
为什么当我点击提交按钮时,我的参数 List lst 为空。 我想执行保存。
谢谢。
【问题讨论】:
标签: asp.net asp.net-mvc-2 linq-to-entities entity-framework-4