10

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?

Chad
  • 1,531
  • 3
  • 20
  • 46
SRA
  • 1,681
  • 7
  • 27
  • 49

3 Answers3

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

or in the controller action that renders this view:

model.Gender = "Male";
return View(model);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 1
    Sorry Darin, This is not working. Is there any alternate solution ? – SRA Jul 01 '10 at 06:06
  • 1
    Sure it is working, I've just created a sample ASP.MVC project, put a view model with a single property `Gender` (of type string), and in the view used HTML attributes to set the `checked` property. – Darin Dimitrov Jul 01 '10 at 06:14
6

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" }) %>
SiwachGaurav
  • 1,918
  • 2
  • 17
  • 16
3

TRY:

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

Worked in my case.

Amit Singh
  • 31
  • 1