I have this code
@Html.RadioButtonFor(model => model.LivStato, 1, Model.LivStato == 1)
@Html.RadioButtonFor(model => model.LivStato, -1, Convert.ToString(Model.LivStato) == string.Empty)
If Model.LivStato == 1 is true, the radio button is checked.
I don’t understand why if Convert.ToString(Model.LivStato) == string.Empty is true, the radio button is not checked
I also try this
@Html.RadioButtonFor(model => model.LivStato, -1, !Model.LivStato.HasValue)
but don’t work.
In the model:
public short? LivStato { get; set; }
Can anyone help me?
Look at
HtmlHelper.RadioButtonForoverloads : no one uses a boolean third parameter as “check button if value == something”. Third parameter (when it exists) is just here for htmlAttributes.http://msdn.microsoft.com/en-us/library/ee830415%28v=vs.108%29
If your firstLine works, it’s just because you use
1as second parameter (Model.LivStato == 1doesn’t do anything).You may try (untested)
and change -1 to null in your controller.