Asp.net-Mvc-2

如何在 ASp.net MVC 2 中將 RadioButtonFor() 設置為預設選中

  • April 8, 2010

我如何將 RadioButtonFor() 設置為預設選中

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

(Html.RadioButton) 有出路,但 (Html.RadioButtonFor) 沒有出路

有任何想法嗎?

StackOverflow 上的這個問題涉及 RadioButtonListFor 並且答案也解決了您的問題。您可以在 RadioButtonListViewModel 中設置 selected 屬性。

使用簡單的方法:

<%= Html.RadioButtonFor(m => m.Gender, "Male", new { Checked = "checked" })%>

引用自:https://stackoverflow.com/questions/2598668