how to select a radio button by default - asp.net mvc strongly typed html helpers

38,659

Solution 1

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

or in the controller action that renders this view:

model.Gender = "Male";
return View(model);

Solution 2

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" }) %>

Solution 3

TRY:

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

Worked in my case.

Share:
38,659
SRA
Author by

SRA

A Asp.net, c# developer

Updated on June 05, 2020

Comments

  • SRA
    SRA about 4 years

    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?