2013-05-27 131 views
0

我正在創建一個web應用程序,我希望用戶的單個選擇(槽單選按鈕)將值傳遞給我的表上的兩個不同的列(一個字符串和一個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> 

什麼我希望會是這樣的(我知道不工作):

@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 

沒什麼特別的,但工程。

相關問題