0

In these code I have a strange situation:

@foreach (var subs in getSubscriptionTypes())
{
    <p>@Html.RadioButton(subs.LengthMonths.ToString(), subs.Price) @subs.LengthMonths</p>
}

I get properly all of subs, but radiobuttons behave very strange - I can check all of radiobuttons, but I want to check only one (one is true, then rest is false). How to repair it?

Regards.

4

1 回答 1

1

每个单选按钮的第一个参数必须相同,它们才能互斥(请参阅此演示)。

所以试试:

<p>@Html.RadioButton("subtype", subs.Price) @subs.LengthMonths</p>

为了获得更好的用户界面,您还可以添加标签元素using@Html.Label(...)以便用户可以单击文本以选择单选:

<p>
    @Html.RadioButton("subtype", subs.Price, new { id = "subtype-" + subs.Price })
    @Html.Label("subtype-" + subs.Price, @subs.LengthMonths)
</p>
于 2013-07-12T13:34:04.590 回答