ビュー内でforeachループを使用して、いくつかのラジオボタン行を表示しています。
sample radiobutton
<tr>
<td width="30%">
Integrity
</td>
<td width="17%">@Html.RadioButtonFor(x => x.main.ElementAt(i).nested.integrity, 1, new { id = "main_" + i + "__nested_integrity) Poor
</td>
<td width="18%">@Html.RadioButtonFor(x => x.main.ElementAt(i).nested.integrity, 2, new { id = "main_" + i + "__nested_integrity" }) Satisfactory
</td>
<td width="18%">@Html.RadioButtonFor(x => x.main.ElementAt(i).nested.integrity, 3, new { id = "main_" + i + "__nested_integrity" }) Outstanding
</td>
<td width="16%">@Html.RadioButtonFor(x => x.main.ElementAt(i).nested.integrity, 4, new { id = "main_" + i + "__nested_integrity" }) Off
</td>
</tr>
モデルのバインド中に問題が発生したため、要件に合わせて手動IDを作成しました(異なる増分ID)。
しかし、やはり問題は名前属性にあると思います。最初とすべてのループで、同じ名前属性(インクリメントされない)を取得しています。つまり、最初のループからradiobuttonを選択すると、他のループから行の選択が解除されます。
好き
Loop1 id= "main_0__nested_integrity"
Loop2 id= "main_0__nested_integrity"
Loop1 name= "nested.integrity"
Loop2 name= "nested.integrity"
ご覧のとおり、すべてのループのname属性は同じで、IDが異なります。
今私の質問は...RadioButtonForのname属性をidのようにオーバーライドすることは可能ですか?