How to Set RadioButtonFor() in ASp.net MVC 2 as Checked by default

前端 未结 14 1840
一向
一向 2021-02-06 21:20

How can i Set RadioButtonFor() as Checked By Default

<%=Html.RadioButtonFor(m => m.Gender,\"Male\")%>

there is way out for (Html.Radio

14条回答
  •  再見小時候
    2021-02-06 21:42

    You can also add labels that are tied to your radio buttons with the same ID, which then allows the user to click the radio button or label to select that item. I'm using constants here for "Male", "Female" and "Unknown", but obviously these could be strings in your model.

    <%: Html.RadioButtonFor(m => m.Gender, "Male", 
        new Dictionary { { "checked", "checked" }, { "id", "Male" } }) %>
    <%: Html.Label("Male") %>
    
    <%: Html.RadioButtonFor(m => m.Gender, "Female", 
        new Dictionary { { "id", "Female" } }) %>
    <%: Html.Label("Female")%>
    
    <%: Html.RadioButtonFor(m => m.Gender, "Unknown",
        new Dictionary { { "id", "Unknown" } }) %>
    <%: Html.Label("Unknown")%>
    

提交回复
热议问题