【发布时间】:2011-03-10 03:04:57
【问题描述】:
我有一个像这样的单选按钮列表:
<%=Html.RadioButtonFor(m => m.Gender,"Male")%>
我希望默认选中此按钮。我该怎么做?
【问题讨论】:
标签: html asp.net-mvc html-helper
我有一个像这样的单选按钮列表:
<%=Html.RadioButtonFor(m => m.Gender,"Male")%>
我希望默认选中此按钮。我该怎么做?
【问题讨论】:
标签: html asp.net-mvc html-helper
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
或在呈现此视图的控制器操作中:
model.Gender = "Male";
return View(model);
【讨论】:
Gender(字符串类型)的视图模型,并在视图中使用了 HTML 属性设置checked 属性。
如果你使用 Razor view strong,你可以使用这样的单选按钮
@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" }) %>
【讨论】:
试一试:
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { Checked = true }) %>
在我的情况下工作。
【讨论】: