Here's my model:
[Required]
[Display(Name = "I'm a:")]
public bool Sex { get; set; }
And my editor template:
<div>
@Html.LabelFor(model => model.RegisterModel.Sex)
@Html.EditorFor(model => model.RegisterModel.Sex)
</div>
However this render to the following:
<div>
<label for="RegisterModel_Sex">Soy:</label>
<input class="check-box" data-val="true" data-val-required="The Soy: field is required." id="RegisterModel_Sex" name="RegisterModel.Sex" type="checkbox" value="true" /><input name="RegisterModel.Sex" type="hidden" value="false" />
</div>
How would I render some nice radio buttons for Male and Female? What datatype would my model have to have?
Edit:
Here's my new updated code:
//Model:
[Required]
[Display(Name = "Soy:")]
public Gender Sex { get; set; }
}
public enum Gender
{
Male = 1,
Female = 2
}
//Viewmodel:
<fieldset>
<legend>Informacion Personal</legend>
<div>
@Html.LabelFor(model => model.RegisterModel.Nombre)
@Html.EditorFor(model => model.RegisterModel.Nombre)
</div>
<div>
@Html.LabelFor(model => model.RegisterModel.Apellido)
@Html.EditorFor(model => model.RegisterModel.Apellido)
</div>
<div>
@Html.LabelFor(model => model.RegisterModel.Sex)
@Html.EditorFor(model => model.RegisterModel.Sex)
</div>
<div>
@Html.LabelFor(model => model.RegisterModel.Carnet)
@Html.EditorFor(model => model.RegisterModel.Carnet)
</div>
</fieldset>
//EditorTemplate:
@model GoldRemate.WebUI.Models.Gender
@{
ViewBag.Title = "Gender";
}
<input type="radio" name="Sex" value="@Model" />
When I run this, I get this error:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'GoldRemate.WebUI.Models.Gender'.
What is causing this and how can I show the values of my enum in my form?