title: Asp.net MVC DisplayTemplate Subfolders
body: <p>Simple question - is this allowed? if so, how do i do it?</p>
  
  <p>As an example, say i have the following:</p>
  
  <pre><code>namespace Model.Event{
      public class Type1{
  
          [UIHint("Child")]
          public Child Child{ get; set; }
  
          [UIHint("AnotherClass")]
          public Model.Event.SubNameSpace.AnotherClass AnotherClass{ get; set; }
  
          [UIHint("Child")]
          Public Model.Event.SubNameSpace.Child Child2{ get; set; }
      }
  
      public class Child{
          public string SomeText{ get; set; }
      } 
  }
  
  namespace Model.Event.SubNameSpace{
      public class AnotherClass{
          public string SomeText2{ get; set; }
      }
  
      public class Child{
          public string SomeText2{ get; set; }
      }
  }
  </code></pre>
  
  <p>and in the Views/Shared I have the following structure:</p>
  
  <p>Views/Shared/DisplayTemplates/Model/Event/Type1.ascx</p>
  
  <pre><code>@Model Model.Event.Type1
      @DisplayFor(x=&gt;x.Child)
      @DisplayFor(x=&gt;x.AnotherClass)
      @DisplayFor(x=.x.Child2)
  </code></pre>
  
  <p>Views/Shared/DisplayTemplates/Model/Event/Child.ascx</p>
  
  <pre><code>@Model Model.Event.Child
      @DisplayFor(x=&gt;x.SomeText)
  </code></pre>
  
  <p>Views/Shared/DisplayTemplates/Model/Event/SubNameSpace/AnotherClass.ascx</p>
  
  <pre><code> @Model Model.Event.SubNameSpace.AnotherClass
      @DisplayFor(x=&gt;x.SomeText2)
  </code></pre>
  
  <p>Views/Shared/DisplayTemplates/Model/Event/SubNameSpace/Child.ascx</p>
  
  <pre><code> @Model Model.Event.SubNameSpace.Child
      @DisplayFor(x=&gt;x.SomeText2)
  </code></pre>
  
  <p>I then create a ViewModel as:</p>
  
  <pre><code>public class MyViewModel(){
      [UIHint("Type1")]
      public Model.Event.Type1 {get; set; }
  }
  </code></pre>
  
  <p>and then in the view I want to say</p>
  
  <pre><code>@Model Model.Event.Type1
      @DisplayFor(x=&gt;x.Child)
  </code></pre>
  
  <p>I want it to then give me the Type1.ascx
  and because of the UIHint attributes, give me the child views - does that make sense?</p>