views:

251

answers:

1

In a asp.net mvc form, im using a radiobutton set, to set a property.

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

I need the CType or i get an overload error.

This case seems like the most commom use of radiobutton when working with a Model property.

Of course i could create a partial view or a control, but apart from that, is there a cleaner code to accomplish this?

A: 

I'm not sure why you're using CType... why not

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

or

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