Adding a custom class to Radio Buttons in ASP.NET MVC 4

user2377475 picture user2377475 · Dec 26, 2013 · Viewed 11.5k times · Source

I'm trying to add Bootstrap classes to a set of radio buttons.

@Html.RadioButtonFor(model => model.Male, !Model.Male) Female
@Html.RadioButtonFor(model => model.Male, Model.Male) Male

Just don't seem to get the right way of doing it. Any help appreciated. Thanks

Answer

Zabavsky picture Zabavsky · Dec 26, 2013
@Html.RadioButtonFor(model => model.Male, !Model.Male, new { @class = "female"})
@Html.LabelFor(model => model.Male, "Female", new { @class = "female"})

@Html.RadioButtonFor(model => model.Male, Model.Male, new { @class = "male"})
@Html.LabelFor(model => model.Male, "Male", new { @class = "male"})