title: MVC model for dynamic survey form
body: <p>Consider a dynamic survey form that consit of <strong>n questions</strong> and for each question there can be <strong>n answers</strong></p>
  
  <pre><code>&lt;form&gt;
  &lt;!-- Question block --&gt;
      &lt;input id="QuestionText" name="QuestionText" placeholder="Text otázky" value="" type="text"&gt;
      &lt;table&gt;
          &lt;!-- Answer block --&gt;
          &lt;tr&gt;&lt;td&gt;&lt;input name="AnswerIsCorrect" type="checkbox"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="AnswerText" type="text"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;!-- Answer block END --&gt;
          &lt;tr&gt;&lt;td&gt;&lt;input name="AnswerIsCorrect" type="checkbox"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="AnswerText" type="text"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;!-- More answers --&gt;
      &lt;/table&gt;
      &lt;input id="QuestionComment" type="text"&gt;
      &lt;!-- Question block END --&gt;
  
      &lt;!-- More questions --&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Is it possible to have MVC parse it <strong>on submit</strong> to similar structure as:</p>
  
  <pre><code>public  class CreateSurveyModel
  {
      public List&lt;QuestionModel&gt; Questions { get; set; }
  }
  public class QuestionModel
  {
      public string QuestionText { get; set; }
      public string QuestionComment { get; set; }
      public List&lt;AnswerModel&gt; Answers { get; set; }
  }
  public class AnswerModel
  {
      public string AnswerText { get; set; }
      public bool IsCorrect { get; set; }
  }
  </code></pre>
  
  <p>If so how?</p>
  
  <p><strong>EDIT (as suggested in the answers):</strong></p>
  
  <pre><code>@using(Html.BeginForm("Send", "Try", FormMethod.Post/*or FormMethod.Get*/))
  {
      foreach(var question in Model.Questions)
      {
          &lt;!-- Question block --&gt;
  
           @Html.TextBox("QuestionText", question.QuestionText)            
           &lt;table&gt;
               @foreach(var answer in question.Answers)
               {
                   &lt;!-- Answer block --&gt;
                   &lt;tr&gt;
                       &lt;td&gt;@Html.CheckBox("AnswerIsCorrect", answer.IsCorrect)&lt;/td&gt;
                       &lt;td&gt;@Html.TextBox("AnswerText", answer.AnswerText )&lt;/td&gt;
                   &lt;/tr&gt;
                   &lt;!-- Answer block END --&gt;
               }
           &lt;/table&gt;
           @Html.TextBox("QuestionComment", question.QuestionComment)
           &lt;!-- Question block END --&gt;
      }
      &lt;input type="submit"/&gt;
  }
  </code></pre>
  
  <p>And action:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Send(CreateSurveyModel model)
  {
      return Index();
  }
  </code></pre>
  
  <p>But model.Questions is null</p>