Search code examples
asp.net-mvcrazorwebforms

Default radiobuttonlist in ASP.NET MVC Razor


How do I ensure that a radio button list has the first option selected? If it is based on the model property, how is this set if this is the first page that is shown on application start-up?

This is easy peasy in webforms but I don't know how to do this in MVC and there doesn't seem to be anywhere on the NET which shows how this is done.

This doesn't seem to work:

@Html.RadioButtonFor(m => m.SearchType, true) Location
@Html.RadioButtonFor(m => m.SearchType, false) Name

I Just get both radio buttons unselected??


Solution

  • @Html.RadioButtonFor(x => x.Something, "radioValue", new { @checked = true })