title: How to make query parameters required for complex type in ASP.NET Web API
body: <p>I have a controller with the following action:</p>
  
  <pre><code>public class MyController
  {
      public IHttpActionResult GetSomething([FromUri] int param1, [FromUri] int param2 = 2)
      {
          // some code...
      }
  }
  </code></pre>
  
  <p>In this case, if I do a request with <a href="http://localhost/myapi/My/Something?param=1" rel="nofollow noreferrer">http://localhost/myapi/My/Something?param=1</a> then everything is OK, param1 is required and param2 gets its default value. If I do <a href="http://localhost/myapi/My/Something" rel="nofollow noreferrer">http://localhost/myapi/My/Something</a> I get "No HTTP resource was found that match the request URI" which is also OK.</p>
  
  <p>But then if I change my method signature to </p>
  
  <pre><code>public IHttpActionResult GetSomething([FromUri] RequestParames request)
  </code></pre>
  
  <p>where</p>
  
  <pre><code>public class RequestParames
  {
      public int Param1 {get; set;}
      public int Param2 {get; set;} = 2;
  }
  </code></pre>
  
  <p>In this case, WebAPI can't determine which of my complex type properties are required and which are optional, all become optional. So if I request <a href="http://localhost/myapi/My/Something" rel="nofollow noreferrer">http://localhost/myapi/My/Something</a> I don't get any error which is bad as my internal code expects it to be provided.</p>
  
  <p>So the question is if there is some way to mark my complex type properties to be required?</p>