Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Brad Wilsons blog here <a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html" rel="noreferrer">http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html</a> has an example about DisplayTemplates and EditorTemplates for Custom Objects, and it discusses issues which may be helpful in resolving your question.</p> <p>Regarding your first question, it is <strong>important</strong> that your template resides in a folder which the system looks for matching names in, e.g.</p> <pre><code> ~/Views/ControllerName/DisplayTemplates/TemplateName.aspx &amp; .ascx ~/Views/Shared/DisplayTemplates/TemplateName.aspx &amp; .ascx </code></pre> <p>(Replace DisplayTemplates with EditorTemplates for the search paths for editor templates.)</p> <p>The following template names are tried in order:</p> <ul> <li>TemplateHint from ModelMetadata</li> <li>DataTypeName from ModelMetadata</li> <li>The name of the type (see notes below)</li> <li>If the object is not complex: “String”</li> <li>If the object is complex and an interface: “Object”</li> <li>If the object is complex and not an interface: Recurse through the inheritance hiearchy for the type, trying every type name</li> </ul> <p>I'm not sure about an answer for your second question. Is it right to assume that var c is actually effectively Account c? And when you are writing <code>Html.DisplayFor(x =&gt; x)</code> you might as well be writing <code>Html.DisplayModelFor(c =&gt; c)</code> ? Or do you want to have `Html.DisplayFor(x => x.AccountName), for instance?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload