I defined this editorTemplate to modify the behaviour of a boolean type, my problem is when the type is nullable I want to create a combo to change the default values, to what I want, but I don’t know how to select the value that come’s from the model.
For example if the value is true I want the dropdownlist selected with SI value and false with NO. Now, I know that I can get the value of the model like this Model.Value but i don’t know how to pass to the seleclist depending of the model. Here’s my editorTemplate
@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.DropDownList("", listItems)
}
else
{
@Html.CheckBox("", ViewData.Model.Value)
}
You can set this on the
SelectListItem: http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlistitem%28v=VS.100%29.aspx