Created
December 18, 2013 07:06
-
-
Save anthonyvscode/8018447 to your computer and use it in GitHub Desktop.
MVC EditorTemplate for Nullable Booleans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model bool? | |
@if (ViewData.ModelMetadata.IsNullableValueType) { | |
var items = new[] | |
{ | |
new SelectListItem { Value = "", Text = "N/A" }, | |
new SelectListItem { Value = "true", Text = "Yes" }, | |
new SelectListItem { Value = "false", Text = "No" } | |
}; | |
@Html.DropDownList("", new SelectList(items, "Value", "Text", Model.HasValue ? (Model.Value ? "true" : "false") : "")) | |
} else { | |
@Html.CheckBox(string.Empty, Model.GetValueOrDefault(false)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment