Saturday, June 11, 2016

RadioButtonFor is the Razor means for doing radio buttons.

If our model has a bool type getsetter called IsToUseSpecificCulture we could have a radio button in a .cshtml view like so:

@Html.RadioButtonFor(m => m.IsToUseSpecificCulture, false)

 
 

That just makes the false radio button and one radio button by itself is no fun. You have to have a sister or sister radio button(s) elsewhere in markup like so:

@Html.RadioButtonFor(m => m.IsToUseSpecificCulture, true)

 
 

The two together should provide our true/false toggle. The setting on the getsetter will drive which radio button starts out as checked. I haven't tried to manually set a setting in the markup, but I think you may do so like this based on what I'm Googling as I type this up:

@Html.RadioButtonFor(m => m.IsToUseSpecificCulture, false, new {@checked=true})

No comments:

Post a Comment