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