how to select a radio button by default - asp.net

2019-06-17 07:16发布

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?

3条回答
别忘想泡老子
2楼-- · 2019-06-17 07:45

if u are using Razor view strong you can use use radio button like this

  @Html.RadioButtonFor(model => model.PrintOrder, "Sequential", new {@checked="true"})    Sequential  

as your need correct it as Razor view

  @Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" })

Aspx view

  <%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
查看更多
乱世女痞
3楼-- · 2019-06-17 07:50
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>

or in the controller action that renders this view:

model.Gender = "Male";
return View(model);
查看更多
可以哭但决不认输i
4楼-- · 2019-06-17 08:00

TRY:

<%: Html.RadioButtonFor(x => x.Gender, "Male", new { Checked = true }) %>

Worked in my case.

查看更多
登录 后发表回答