MVC中使用RadioButtonFor


1 进行初始化

<%=Html.RadioButtonFor(model => model.TypeState, 0, new { @id = "radio2", @name = "rdolstState" })%>启用                                                                  
<%=Html.RadioButtonFor(model => model.TypeState, 1, new { @id = "radio1", @name = "rdolstState",@checked=true })%>禁用

注意:htmlAbrritbutes属性的使用  “new{…………………………  }”;

2 编辑时,绑定值,根据数据显示RadioButtonFor选中状态

<%=Html.RadioButtonFor(model => model.TypeState, 0, new { @id = "radio2", @name = "rdolstState" })%>启用                                                                  
<%=Html.RadioButtonFor(model => model.TypeState, 1, new { @id = "radio1", @name = "rdolstState" })%>禁用  

说明:当数据中“TypeState”是0时,这第一条会显示被选中,反之,就是第二条显示选中。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM