는 MVC 제출에 그것을 구문 분석이 가질 수 있습니다 N 질문 및 각 질문에 대한 consit이 n은MVC 모델
<form>
<!-- Question block -->
<input id="QuestionText" name="QuestionText" placeholder="Text otázky" value="" type="text">
<table>
<!-- Answer block -->
<tr><td><input name="AnswerIsCorrect" type="checkbox"></td>
<td><input name="AnswerText" type="text"></td>
</tr>
<!-- Answer block END -->
<tr><td><input name="AnswerIsCorrect" type="checkbox"></td>
<td><input name="AnswerText" type="text"></td>
</tr>
<!-- More answers -->
</table>
<input id="QuestionComment" type="text">
<!-- Question block END -->
<!-- More questions -->
</form>
응답이있을 수있는 동적 설문 조사 양식을 고려과 유사한 구조의 예 :
public class CreateSurveyModel
{
public List<QuestionModel> Questions { get; set; }
}
public class QuestionModel
{
public string QuestionText { get; set; }
public string QuestionComment { get; set; }
public List<AnswerModel> Answers { get; set; }
}
public class AnswerModel
{
public string AnswerText { get; set; }
public bool IsCorrect { get; set; }
}
그렇다면 어떻게 될까요? (답변에서 제안)
편집 :
@using(Html.BeginForm("Send", "Try", FormMethod.Post/*or FormMethod.Get*/))
{
foreach(var question in Model.Questions)
{
<!-- Question block -->
@Html.TextBox("QuestionText", question.QuestionText)
<table>
@foreach(var answer in question.Answers)
{
<!-- Answer block -->
<tr>
<td>@Html.CheckBox("AnswerIsCorrect", answer.IsCorrect)</td>
<td>@Html.TextBox("AnswerText", answer.AnswerText)</td>
</tr>
<!-- Answer block END -->
}
</table>
@Html.TextBox("QuestionComment", question.QuestionComment)
<!-- Question block END -->
}
<input type="submit"/>
}
그리고 조치 :
[HttpPost]
public ActionResult Send(CreateSurveyModel model)
{
return Index();
}
그러나 model.Questions가 null
당신은 마크 업을 통해 제어 할 수 있습니까? – Andrei
예 마크 업을 제어 할 수 있습니다. –