MVC in visual basic

0

I have this code which allows me to access the values from a texbox

@Html.LabelFor(Function(m) m.apellidos, New With {.class = "control-lebel"})
@Html.TextBoxFor(Function(m) m.apellidos, New With {.class = "form-control"})

I want to do this with a RadioButton "to choose a gender either male or female" as I can use it with the @Html.RadioButtonFor

    
asked by janiwa 26.10.2017 в 08:29
source

1 answer

0

It would be necessary to see how you have defined your model but to see if this example helps you.

If, for example, you have defined an Genero enumeration:

Public Enum Genero
    Femenino
    Masculino
End Enum

And, in your model, a property GeneroPersona of type Genero :

Property GeneroPersona() As Genero

The code in your view could be something like this:

    @Html.LabelFor(Function(m) m.GeneroPersona, New With {.class = "control-label"})
    @Html.RadioButtonFor(Function(m) m.GeneroPersona, Genero.Masculino, New With {.Id = "rdMasculino" })
    <label for="rdMasculino">Masculino</label>
    @Html.RadioButtonFor(Function(m) m.GeneroPersona, Genero.Femenino, New With {.Id = "rdFemenino"})
    <label for="rdFemenino">Femenino</label>

The RadioButtonFor method creates the radiobuttons and assigned you a Id specific to be able to associate a label with each one.

    
answered by 26.10.2017 в 08:57