I have the following model:
public class Person
{
public string Name { get; set; }
public string Gender { get; set; }
}
I want the default gender to be female, so I set this in action:
public ActionResult Create()
{
var model = new Person { Gender = "F" };
return View(model);
}
Finally, the view displays everything like this:
@model Person
@using (Html.BeginForm())
{
@Html.EditorForModel()
<p><input type="submit" value="Create" /></p>
}
Everything works as expected. Now let's say that instead of a simple text field, I want to show the floor as a more intuitive pair of radio buttons. So I make the following template and save it in Shared / EditorTemplates / Gender.cshtml:
@model string
@Html.RadioButtonFor(model => model, "F") Female
@Html.RadioButtonFor(model => model, "M") Male
Finally, I decorate the floor [UIHint("Gender")].
Paul is now correctly displayed using the switches, which is great, BUT ...
Problem
A woman is no longer selected as the default, and instead I end up with two radio consoles. Did I miss something?
, RadioButtonFor ( model => model model => model.Gender), , . , , - , , , .