title: Subfolders in controllers and views
body: <p>I wanted to have more than one controller and view for same object/model in asp.net mvc, but it turned out to be a little complicated than I expected.</p>
  
  <p>Basically what I want to do is something like this :</p>
  
  <pre>
  site.com/product
      ->  will show product details to visitors.
  
  site.com/admin/product
      ->  will show some extra information together with product details.
          and some commands like delete, edit etc.
  </pre>
  
  <p>The goal is to seperate the urls for the visitors and the admins.</p>
  
  <p>My first approach was that I'd create a subfolder in the controller and the view folders, so the things would look this way :</p>
  
  <pre>
  > Controllers
      > Admin
          ProductController.cs
      ProductController.cs
  > Views
      > Admin
          > Product
              Index.aspx
      > Product
          Index.aspx
  </pre>
  
  <p>I can map the urls to the correct controllers without a problem (provided that I specify their namespaces, since the class names are the same).
  However, when I return the view from the Controller under admin folder, it does not display the Index view under the Views/Admin/Product folder but the one under Views/Product.</p>
  
  <p>I know I can say <code>return View("Full path here")</code> to return the view I want. But that's obviously not a good solution and I don't want to do that.</p>
  
  <p>My question is, what is the best way to take care of this situation, with the condition of urls having to be that way?</p>
  
  <ul>
  <li><p>Create a custom controller class that overrides the view method (or any other ones that needs to be overriden for this purpose) and makes sure the correct view is returned?</p>
  
  <ul>
  <li>This one is an ugly hack, but would work.</li>
  </ul></li>
  <li><p>Create a custom view engine that also takes folders into consideration?</p>
  
  <ul>
  <li>I don't exactly know how I can do this, but as far as I understand, this should also solve the problem</li>
  </ul></li>
  <li><p>Use <a href="http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx" rel="nofollow noreferrer">Areas Prototype</a> of <a href="http://haacked.com" rel="nofollow noreferrer">Phil Haack</a>?</p>
  
  <ul>
  <li>This one actually uses a different layout for folders, but in theory this should also work. But I am still not sure if this is the best way to do this, because having different Controller &amp; View folders under the different parts of the site is not exactly what I want.
  </li>
  </ul></li>
  </ul>
  
  <p>I'm leaning towards the custom view engine idea, that takes the folders into consideration when returns the views, but like I said, I don't know how to do that.</p>
  
  <p>Any suggestions?</p>