Currently i am creating two buttons and setting the selected value this way:
@if (Model.Test_Emne == null)
{
@Html.RadioButtonFor(x => x.Test_Emne, 1) <span>Ja</span>
<br />
@Html.RadioButtonFor(x => x.Test_Emne, 0) <span>Nej</span>
}
@if (Model.Test_Emne == true)
{
@Html.RadioButtonFor(x => x.Test_Emne, 1, new { @checked = "checked" }) <span>Ja</span>
<br />
@Html.RadioButtonFor(x => x.Test_Emne, 0) <span>Nej</span>
} else if (Model.Test_Emne == false)
{
@Html.RadioButtonFor(x => x.Test_Emne, 1) <span>Ja</span>
<br />
@Html.RadioButtonFor(x => x.Test_Emne, 0, new { @checked = "checked" }) <span>Nej</span>
}
I have a lot of radio buttons on my page, so i am looking for a way to do this with less code.
I have also seen:
Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?
and
http://jonlanceley.blogspot.com/2011/06/mvc3-radiobuttonlist-helper.html
Are these the only options?