6
我有一個單選按鈕,列表如下:如何選擇默認單選按鈕 - asp.net mvc的強類型HTML輔助
<%=Html.RadioButtonFor(m => m.Gender,"Male")%>
我想這個按鈕默認選擇。我該怎麼做呢?
我有一個單選按鈕,列表如下:如何選擇默認單選按鈕 - asp.net mvc的強類型HTML輔助
<%=Html.RadioButtonFor(m => m.Gender,"Male")%>
我想這個按鈕默認選擇。我該怎麼做呢?
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
或呈現此視圖控制器動作:
model.Gender = "Male";
return View(model);
如果u使用Razor視圖強,你可以使用使用單選按鈕,這樣
@Html.RadioButtonFor(model => model.PrintOrder, "Sequential", new {@checked="true"}) Sequential
爲您需要更正爲 剃刀視圖
@Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" })
.aspx的視圖
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
對不起達林,這是行不通的。有沒有其他解決方案? – SRA 2010-07-01 06:06:13
確定它正在工作,我剛剛創建了一個示例ASP.MVC項目,將一個視圖模型放入一個屬性'Gender'(字符串類型),並在視圖中使用HTML屬性來設置'checked'屬性。 – 2010-07-01 06:14:43