RadioButtonFor in ASP.NET MVC 2

2019-02-12 03:00发布

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?

2条回答
冷血范
2楼-- · 2019-02-12 03:30

This question on StackOverflow deals with RadioButtonListFor and the answer addresses your question too (@Larsenal it also includes labels with the "for" attribute)

查看更多
该账号已被封号
3楼-- · 2019-02-12 03:38
Male: <%= Html.RadioButtonFor(x => x.Gender, "Male") %>
Female: <%= Html.RadioButtonFor(x => x.Gender, "Female") %>
查看更多
登录 后发表回答