I have a survey form. The questions and options are generated from the database. There are 5 questions in the form, each are generated using the partial view.
The question is a partial view and the options are templated view.
The problem is when submitting the form and the user did not select an answer, it will show a validationsummary
. The problem is the selected answers are gone.
Partial View
<% for(var x = 0; x < Model.QuestionOptions.Count(); x++){%>
<% var option = Model.QuestionOptions.ToList()[x]; %>
<li>
<%: Html.EditorFor(model => option, "RadioButton")%>
</li>
<% } %>
radio button template
<%: Html.RadioButton("OptionId", Model.O开发者_StackOverflow社区ptionId, false)%>
you can do the validation on the client side
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
精彩评论