代码之家  ›  专栏  ›  技术社区  ›  ariel

asp.net mvc:使用html.radiobutton的最佳方法

  •  0
  • ariel  · 技术社区  · 16 年前

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

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

    这个例子似乎是处理模型属性时最常用的单选按钮。

    当然,我可以创建一个局部视图或控件,但除此之外,是否有更干净的代码来实现这一点?

    1 回复  |  直到 16 年前
        1
  •  1
  •   Odd    16 年前

    <%=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>
    
    推荐文章