title: Can model classes be placed inside a controller class
body: <p>Apologies if this is answered elsewhere; the only search results turned up PHP-based answers.</p>
  
  <p>TL;DR - Can ASP.NET API/MVC model classes be declared inside a controller class, and are there any gotcha's when doing this?</p>
  
  <p>I have many controllers that accept multiple parameters.  Based on <a href="https://stackoverflow.com/a/14407502/792888">this answer</a>, and <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api" rel="nofollow noreferrer">Mike Wasson's blog</a>, the general consensus seems to be that a complex-type parameter is best, e.g.</p>
  
  <pre><code>public class MyController : ApiController 
  {
      [HttpPost]
      public HttpResponseMessage Post([FromBody] MyModel ModelParam)
      {
         // do something with ModelParam.Param1, ModelParam.Param2, etc...
      }
  }
  </code></pre>
  
  <p>I have always put classes in the <code>Models</code> folder of the application, but I'm finding that my models are only being used once per controller, so I end up with as many models as I have controllers.  </p>
  
  <p>Perhaps I'm doing something wrong right there, but could each model live inside the controller, so the relevant logic is together?  For example...</p>
  
  <pre><code>public class MyController : ApiController 
  {
      public class MyModel
      {
          public string Param1{ get; set; }
          public DateTime Param2{ get; set; }
      }
  
      [HttpPost]
      public HttpResponseMessage Post([FromBody] MyModel ModelParam)
      {
         // do something with ModelParam.Param1, ModelParam.Param2, etc...
      }
  }
  </code></pre>
  
  <p>I tried this, and it seems to compile and run okay.  Previously when using webforms I got bitten badly by putting classes in pages (an intermittent error similar to "Cannot cast type "MyClass" to type "MyClass").  I am nervous as to whether there are any issues with this approach (or is it bad practice)?</p>