Asp.net-mvc – RadioButtonFor in ASP.NET MVC 2

asp.net-mvcasp.net-mvc-2radiobuttonfor

Can someone provide a simple example of how to properly use Html.RadioButtonFor? Let's say it's a simple scenario where my model has a string property named Gender. I want to display two radio buttons: "Male" and "Female".

What is the most clean way to implement this while retaining the selected value in an Edit view?

Best Answer

Male: <%= Html.RadioButtonFor(x => x.Gender, "Male") %>
Female: <%= Html.RadioButtonFor(x => x.Gender, "Female") %>