2012-03-03 2 views
19

양식에 몇 가지 옵션 버튼이 있으며 선택하기 위해 항상 둥근 옵션 버튼을 정확히 클릭해야합니다. 사용자가 관련 레이블을 클릭하여 옵션 버튼을 선택할 수있게하는 방법이 있습니까? 레이블 요소를 라디오 버튼과 연결하는 방법

<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> 

enter image description here

나는 여기에 몇 가지 해결책을 발견 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)'이것은 첫 번째 라디오 옵션을 선택합니다. –

관련 문제