2011-01-23 13 views
0

내가이ASP.NET MVC 2 : 사용자 정의 모델에 Html.EditorFor를 어떻게 사용합니까?

은 가정하자 내가보기 질문 목록을 가지고 (Popup.ascx)를 렌더링 할 MVC 2에서 어떻게 작동하는지 궁금, 나는이 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에 대한 내 생각은 - 그런 다음 사용자가 제출 버튼을 쳤을 때 나는 다시 값을 얻는 방법?

미리 감사드립니다.

답변

관련 문제