我有一個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