I created an editor template for Boolean types, my problem it's when model attribute it's not nullable, the default behaviour of the checkbox are modified, for example if themodel value is true then the checkbox in the view appears without checked. What am I doing wrong??? this is the code.
@model Nullable<bool>
@{
var listItems = new[]
{
new SelectListItem { Value = "null", Text = "Sin Valor" },
new SelectListItem { Value = "true", Text = "Si" },
new SelectListItem { Value = "false", Text = "No" }
};
}
@if (ViewData.ModelMetadata.IsNullableValueType)
{
@Html.DropDownListFor(model => model.Value, listItems)
}
else
{
@Html.CheckBox("", ViewData.TemplateInfo.FormattedModelValue)
}