2013-05-27 111 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 

没什么特别的,但工程。

相关问题