开发者

RadioButtonFor in ASP.NET MVC 2

开发者 https://www.devze.com 2022-12-26 02:21 出处:网络
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

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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消