2012-03-03 14 views
19

フォームにオプションボタンがいくつかあります。丸いオプションボタンをクリックすると、そのボタンをクリックする必要があります。ユーザーが関連するラベルをクリックしてオプションボタンを選択できるようにする方法はありますか?ラベル要素をラジオボタンに関連付ける方法

enter image description here

<p> 
    <span class="editor-label"> 
     @Html.LabelFor(m => m.ADR) 
    </span> 
    <span class="editor-field"> 
     @Html.RadioButtonFor(model => model.ADR, "Yes", AdrYesOptions) 
     @UserResource.YesValue 
     @Html.RadioButtonFor(model => model.ADR, "No", AdrNoOptions) 
     @UserResource.NoValue 

    </span> 
</p> 

私はここにいくつかの解決策が見つかりました:How to associate labels with radio buttonsをしかし、私はMVCのための具体的な解決策を好むので、これらは私に合っていません。

+0

あなたがMVC_ため_specificとはどういう意味ですか?リンクされた質問には、これを達成する方法を示す有効な回答(受け入れられたものではありません)が含まれています。 – marapet

+0

どういう意味ですか(可能であれば)Html.LabelFor ... Html.RadioButtonFor ...

答えて

40

ラップ<label>要素内の各ラジオボタンと関連付けられたラベルのテキスト:

<p> 
    <span class="editor-label"> @Html.LabelFor(m => m.ADR) </span> 
    <span class="editor-field"> 
     <label> @Html.RadioButtonFor(model => model.ADR, "Yes", AdrYesOptions) @UserResource.YesValue </label> 
     <label> @Html.RadioButtonFor(model => model.ADR, "No", AdrNoOptions) @UserResource.NoValue </label> 
    </span> 
</p> 
+1

ユーザがメインラベル ' @ Html.LabelFor(m => m.ADR) 'これは、最初のラジオオプションを選択します。 –

関連する問題