12 のステートメントの複数ページで構成されるアンケートがあります。ユーザーは、ステートメントが一致する度合いをそれぞれのステートメントに対して指定する必要があります。次のようになります。
私のビューモデルは次のようになります。
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; }
}
そして私の見解:
@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"/>
}
そして、アイテムごとに繰り返されるエディタ テンプレート:
@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>
検証の要約に、応答が必要なステートメントがリストされていることを望みます。「ステートメント 6 には応答が必要です」。現在、「応答フィールドが必要です」を繰り返すだけです
カスタムバリデータが必要だと想像する必要がありますが、現時点では自分のものをゼロから作成することは少し難しいので、助けていただければ幸いです。