I'm using MVC and I have some RadioButtons in a foreach:
foreach (var item in group) {
<tr>
<td>
@Html.RadioButtonFor(modelItem => item.CheckerApproved, true)
@Html.RadioButtonFor(modelItem => item.CheckerApproved, false)
</td>
</tr>
}
So for every item in the group there should be a radiobutton for true and false.
The problem is when there are multiple items in the group you might end up with for two items:
<tr>
<td>
<input id="item_CheckerApproved" type="radio" value="True" name="item.CheckerApproved">
<input id="item_CheckerApproved" type="radio" value="False" name="item.CheckerApproved
checked="checked">
</td>
</tr>
<tr>
<td>
<input id="item_CheckerApproved" type="radio" value="True" name="item.CheckerApproved">
<input id="item_CheckerApproved" type="radio" value="False" name="item.CheckerApproved
checked="checked">
</td>
</tr>
What I wanted was for the radiobuttons
groups to be seperate. So changing the value in the first row won't effect the value in the second row. However if you have set say true in the top row then select either value in the second row the true in the first row is cancelled.
I believe this is because they are linked by the name attribute. However you can't actually manually reset this name attribute.
Does anyone know how I could make it work so the true and false for each row interact with each other but there is no effect on radiobuttons
in other rows?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…