0
我想知道这是如何在MVC 2的工作ASP.NET MVC 2:你如何使用Html.EditorFor来定制模型?
假设我想呈现一个视图(Popup.ascx),有一个问题清单,我创建了这些的ViewModels
public class VMPopup
{
public List<VMQuestion> Questions;
}
public class VMQuestion
{
public int Id
public string Question;
public string Answer;
public bool Mandatory;
}
我会在控制器
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Popup(int elementId)
{
List<VMQuestion> questions = new List<VMQuestion>();
// Code to generate the questions
// .....
VMPopup vm = new VMPopup{Questions = questions};
return View(vm);
}
1这样的方法 - 我会放什么看法Popup.ascx?我在这里需要一个BeginForm吗?
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EnterpriseConnectMVC.Controllers.VMPopup>" %>
<table border="1">
<% foreach(var q in Model.Questions) { %>
<%= Html.EditorFor(q); // I know this is wrong, how should I do it? %>
<% } %>
</table>
<input type="submit" value="OK" />
这是我VMQuestion
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EnterpriseConnectMVC.Controllers.VMQuestion>" %>
<tr>
<td><%= Model.Question %></td>
<td>
<%= Html.TextBoxFor(m=>m.Answer) %>
<%= Html.ValidationMessageFor(m=>m.Answer) %>
</td>
</tr>
2视图 - 那么我如何才能值回当用户点击提交按钮?
在此先感谢。