How to choose the default switch - asp.net mvc strongly typed html helpers

I have a list of radio buttons:

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

I want this button to be selected by default. How to do it?

+5
source share
2 answers
<%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>

or in a controller action that displays this view:

model.Gender = "Male";
return View(model);
+16
source

If you use Razor view strong, you can use a radio button like

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

since you need to fix it as a razor view

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

Aspx view

  <%: Html.RadioButtonFor(x => x.Gender, "Male", new { @checked = "checked" }) %>
+6
source

All Articles