Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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??

like image 405
jaffa Avatar asked Nov 28 '22 18:11

jaffa


1 Answers

@Html.RadioButtonFor(x => x.Something, "radioValue", new { @checked = true })
like image 140
Linkgoron Avatar answered Dec 04 '22 09:12

Linkgoron