2013-05-27 3 views
0

웹 앱을 만들고 있는데, 사용자의 단일 선택 (물마리 라디오 버튼)이 내 테이블의 두 개의 다른 열 (하나의 문자열과 하나의 int)에 값을 전달하기를 원합니다.하나의 라디오 버튼으로 여러 값을 전달하는 방법은 무엇입니까?

나는 약간의 면도기 라디오 버튼 구문 우아한 트릭으로 이것을 해결하기를 희망하고 있지만, 모든 솔루션을 환영합니다.

현재 내 코드 단순한 면도기 HTML 도우미입니다 :

  <td> 
       <td>@Html.RadioButtonFor(model => model.MedicationPeriod, "Morning") </td> 
       <td>@Html.LabelFor(model => model.MedicationPeriod, "Morning")</td> 
      </td> 
      <td> 
       <td>@Html.RadioButtonFor(model => model.MedicationPeriod, "Morning and Night")</td> 
       <td>@Html.LabelFor(model => model.MedicationPeriod, "Morning and Night")</td> 
      </td> 

내가 이런 걸 (I이 작동하지 않습니다 알고)가 될 것입니다 무엇을 기대 : 나는 '

@Html.RadioButtonFor(model => model.MedicationPeriod, "Morning", model => model.TimesPerDay, 1) 
@Html.RadioButtonFor(model => model.MedicationPeriod, "Morning and Night", model => model.TimesPerDay, 2) 
+1

코드를 볼 수 있습니까? –

+0

그리고 처음부터 시작해야합니까? 몇 가지 코드를 게시하십시오. –

+0

코드가 추가되었습니다. 나는 이것이 이론적 인 질문이라고 생각했다. 미안하다. – soneca

답변

0

이 두 확장 방법을 만들었습니다. 두 번째 목록은 SelectListItem과 함께 사용할 수 있습니다.

<Extension()> _ 
    Public Function RadioButtonList(ByVal helper As HtmlHelper, ByVal name As String, ByVal Items As IEnumerable(Of String)) As String 
     Dim selectList = New SelectList(Items) 
     Return helper.RadioButtonList(name, selectList) 
    End Function 

    <Extension()> _ 
    Public Function RadioButtonList(ByVal helper As HtmlHelper, ByVal Name As String, ByVal Items As IEnumerable(Of SelectListItem)) As String 
     Dim sb As New StringBuilder 
     sb.Append("<ul class=""radiobuttonlist"">") 
     For Each item In Items 
      sb.AppendFormat("<li><input id=""{0}_{1}"" name=""{0}"" type=""radio"" value=""{1}"" {2} /><label for=""{0}_{1}"" id=""{0}_{1}_Label"">{3}</label></li>", Name, item.Value, If(item.Selected, "selected", ""), item.Text) 
     Next 
     sb.Append("</ul>") 
     Return sb.ToString() 
    End Function 

아무 것도 없지만 작동합니다.

관련 문제