【问题标题】:asp.net mvc: best way to use html.radiobuttonasp.net mvc:使用 html.radiobutton 的最佳方式
【发布时间】:2011-01-21 05:07:23
【问题描述】:

在 asp.net mvc 表单中,我使用单选按钮集来设置属性。

<%=Html.RadioButton("Tipo", "Pizza", 
    CType(Model.Tipo = "Pizza", Boolean), New With {.id = "Pizza"})%>
    <label for="Pizza">Tipo Pizza</label>

<%=Html.RadioButton("Tipo", "Barra", 
    CType(Model.Tipo = "Barra", Boolean), New With {.id = "Barra"})%>
    <label for="Barra">Tipo Barra</label>

我需要 CType,否则我会收到重载错误。

在使用模型属性时,这种情况似乎是单选按钮最常见的用法。

我当然可以创建局部视图或控件,但除此之外,是否有更简洁的代码来完成此操作?

【问题讨论】:

    标签: asp.net asp.net-mvc vb.net radio-button


    【解决方案1】:

    我不确定你为什么要使用 CType...为什么不呢

    <%=Html.RadioButton("Tipo", "Barra", 
        Model.Tipo == "Barra", 
        new { id = "Barra" })%>
    <label for="Barra">Tipo Barra</label>
    

    <%=Html.RadioButton("Tipo", "Barra", 
         Model.Tipo.Equals("Barra"), 
         new { id = "Barra" })%>
    <label for="Barra">Tipo Barra</label>
    

    【讨论】:

      猜你喜欢
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多