Where can I find the default templates for DisplayForModel and EditorForModel?
Found the default templates here:
ASP.NET MVC 3 Futures / http://aspnet.codeplex.com/releases/view/58781
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script runat="server">
bool ShouldShow(ModelMetadata metadata) {
return metadata.ShowForDisplay
&& metadata.ModelType != typeof(System.Data.EntityState)
&& !metadata.IsComplexType
&& !ViewData.TemplateInfo.Visited(metadata);
}
</script>
<% if (Model == null) { %>
<%= ViewData.ModelMetadata.NullDisplayText %>
<% } else if (ViewData.TemplateInfo.TemplateDepth > 1) { %>
<%= ViewData.ModelMetadata.SimpleDisplayText %>
<% } else { %>
<% foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => ShouldShow(pm))) { %>
<% if (prop.HideSurroundingHtml) { %>
<%= Html.Display(prop.PropertyName) %>
<% } else { %>
<% if (!String.IsNullOrEmpty(prop.GetDisplayName())) { %>
<div class="display-label"><%= prop.GetDisplayName() %></div>
<% } %>
<div class="display-field"><%= Html.Display(prop.PropertyName) %></div>
<% } %>
<% } %>
<% } %>
I'm not sure if/where you can see the defaults without looking at the source code but you can create your own in the following directories to override the defaults:
~/Views/Shared/EditorTemplates/Object.cshtml
and
~/Views/Shared/DisplayTemplates/Object.cshtml
Does this help?
Here's a great post on Brad Wilson's blog that will walk you through how to create your own default editor and display templates: ASP.NET MVC 2 Templates, Part 4: Custom Object Templates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With