Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 953
SRA Avatar asked Jun 30 '10 12:06

SRA


2 Answers

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

or in the controller action that renders this view:

model.Gender = "Male";
return View(model);
like image 125
Darin Dimitrov Avatar answered Sep 21 '22 06:09

Darin Dimitrov


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" }) %>
like image 30
SiwachGaurav Avatar answered Sep 18 '22 06:09

SiwachGaurav