Solution: Do like this:
Model:
public class MyViewModel
{
public bool IsFemale { get; set; }
}
Controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel
{
IsFemale = true
});
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
return Content("IsFemale: " + model.IsFemale);
}
}
Model:
@model MyViewModel
@using (Html.BeginForm())
{
@Html.RadioButtonFor(model => model.IsFemale, "false", new { id = "male" })
@Html.Label("male", "Male")
@Html.RadioButtonFor(model => model.IsFemale, "true", new { id = "female" })
@Html.Label("female", "Female")
<button type="submit">OK</button>
}