如何默认选择单选按钮 - asp.net mvc 强类型 html 助手
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3149390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to select a radio button by default - asp.net mvc strongly typed html helpers
提问by SRA
I have a radio button list like this:
我有一个这样的单选按钮列表:
<%=Html.RadioButtonFor(m => m.Gender,"Male")%>
I want this button selected by default. How do I do this?
我希望默认选中此按钮。我该怎么做呢?
回答by Darin Dimitrov
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
or in the controller action that renders this view:
或在呈现此视图的控制器操作中:
model.Gender = "Male";
return View(model);
回答by SiwachGaurav
if u are using Razor view strong you can use use radio button like this
如果您使用 Razor 视图强大,您可以使用这样的单选按钮
@Html.RadioButtonFor(model => model.PrintOrder, "Sequential", new {@checked="true"}) Sequential
as your need correct it as Razor view
根据您的需要将其更正为 Razor 视图
@Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" })
Aspx view
Aspx 视图
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
回答by Amit Singh
TRY:
尝试:
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { Checked = true }) %>
Worked in my case.
在我的情况下工作。