I have a questionnaire that consists of multiple pages of 12 statements, for each of which the user must specify the degree to which the statement matches them. looks like this:
My view model looks like this:
public class PageViewModel
{
public List<ItemViewModel> Items { get; set; }
}
public class ItemViewModel
{
public Guid Id { get; set; }
public int Number { get; set; }
public string Text { get; set; }
[Required]
public int Response { get; set; }
}
And my view:
@model PageViewModel
@using(Html.BeginForm()){
<table>
<tr>
<td></td>
<td></td>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
@Html.EditorFor(model => model.Items)
@Html.ValidationSummary(false)
</table>
<input type="submit"/>
}
and the editor template tahts repeated for each item:
@model ItemViewModel
<tr>
<td>@Model.Number:</td>
<td>@Model.Text</td>
@for(int i = 1; i <= 5; i++){
<td>@Html.RadioButtonFor(model => model.Response, i)</td>
}
<tr>
I would like it if the validation summary would list the statements for which a response is required, eg. "A response is required for statement 6". Currently it is just repeating "The response field is required"
I should imagine a custom validator is required, but writing one of my own from scratch is a bit beyond me at the moment, so any help would be appreciated.