How can we get Asp.Net MVC to display boolean values better?
Lets have a simple model:
public class Options { [Display(Name = "Flux")] public bool EnableFlux { get; set; } [Display(Name = "Advanced Options")] public bool ShowAdvancedOptions { get; set; } [Display(Name = "Do you eat well?")] public bool UserEatsWell { get; set; } }
The default display template isn’t great – it just displays disabled checkboxes:
<h4>Display:</h4> @Html.LabelFor(m => m.ShowAdvancedOptions) @Html.DisplayFor(m => m.ShowAdvancedOptions) @Html.LabelFor(m => m.EnableFlux) @Html.DisplayFor(m => m.EnableFlux) @Html.LabelFor(m => m.UserEatsWell) @Html.DisplayFor(m => m.UserEatsWell)
The result isn’t too pretty: