As Stephen Muecke mentioned in the comments, there are default templates in the System.Web.Mvc.Html
namespace. I think the comment really says it all, but I'll try to clarify what's going on behind the scenes. If you check the source code for EditorFor
you will eventually end up at the internal static
TemplateHelpers
, which contain dictionaries for some default types, which in turn use DefaultEditorTemplates
. These are used until you actually override them yourself by placing a view inside the folders Shared/EditorTemplates
or Shared/DisplayTemplates
. So, even if Boolean
is in the dictionary of the default templates, you may override it by placing Boolean.cshtml
in the on of the folders.
From TemplateHelpers
:
private static readonly Dictionary<string, Func<HtmlHelper, string>> _defaultEditorActions = new Dictionary<string, Func<HtmlHelper, string>>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase) {
{ "HiddenInput", new Func<HtmlHelper, string>(DefaultEditorTemplates.HiddenInputTemplate) },
{ "MultilineText", new Func<HtmlHelper, string>(DefaultEditorTemplates.MultilineTextTemplate) },
{ "Password", new Func<HtmlHelper, string>(DefaultEditorTemplates.PasswordTemplate) },
{ "Text", new Func<HtmlHelper, string>(DefaultEditorTemplates.StringTemplate) },
{ "Collection", new Func<HtmlHelper, string>(DefaultEditorTemplates.CollectionTemplate) },
{ "PhoneNumber", new Func<HtmlHelper, string>(DefaultEditorTemplates.PhoneNumberInputTemplate) },
{ "Url", new Func<HtmlHelper, string>(DefaultEditorTemplates.UrlInputTemplate) },
{ "EmailAddress", new Func<HtmlHelper, string>(DefaultEditorTemplates.EmailAddressInputTemplate) },
{ "DateTime", new Func<HtmlHelper, string>(DefaultEditorTemplates.DateTimeInputTemplate) },
{ "DateTime-local", new Func<HtmlHelper, string>(DefaultEditorTemplates.DateTimeLocalInputTemplate) },
{ "Date", new Func<HtmlHelper, string>(DefaultEditorTemplates.DateInputTemplate) },
{ "Time", new Func<HtmlHelper, string>(DefaultEditorTemplates.TimeInputTemplate) },
{ typeof (Color).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.ColorInputTemplate) },
{ typeof (byte).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.NumberInputTemplate) },
{ typeof (sbyte).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.NumberInputTemplate) },
{ typeof (int).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.NumberInputTemplate) },
{ typeof (uint).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.NumberInputTemplate) },
{ typeof (long).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.NumberInputTemplate) },
{ typeof (ulong).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.NumberInputTemplate) },
{ typeof (bool).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.BooleanTemplate) },
{ typeof (Decimal).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.DecimalTemplate) },
{ typeof (string).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.StringTemplate) },
{ typeof (object).Name, new Func<HtmlHelper, string>(DefaultEditorTemplates.ObjectTemplate) }
};
From DefaultEditorTemplates
for creating a Boolean
:
internal static string BooleanTemplate(HtmlHelper html)
{
bool? nullable1 = new bool?();
if (html.ViewContext.ViewData.Model != null)
nullable1 = new bool?(Convert.ToBoolean(html.ViewContext.ViewData.Model, (IFormatProvider) CultureInfo.InvariantCulture));
if (html.ViewContext.ViewData.ModelMetadata.IsNullableValueType)
return DefaultEditorTemplates.BooleanTemplateDropDownList(html, nullable1);
HtmlHelper html1 = html;
bool? nullable2 = nullable1;
int num = nullable2.HasValue ? (nullable2.GetValueOrDefault() ? 1 : 0) : 0;
return DefaultEditorTemplates.BooleanTemplateCheckbox(html1, num != 0);
}
private static string BooleanTemplateCheckbox(HtmlHelper html, bool value)
{
return InputExtensions.CheckBox(html, string.Empty, value, DefaultEditorTemplates.CreateHtmlAttributes(html, "check-box", (string) null)).ToHtmlString();
}
private static string BooleanTemplateDropDownList(HtmlHelper html, bool? value)
{
return SelectExtensions.DropDownList(html, string.Empty, (IEnumerable<SelectListItem>) DefaultEditorTemplates.TriStateValues(value), DefaultEditorTemplates.CreateHtmlAttributes(html, "list-box tri-state", (string) null)).ToHtmlString();
}
Here's the source code from Core:
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/TemplateRenderer.cs