title: Validation on query string parameters of .Net Core Action Method
body: <p>I have a .Net Core 2.2 Web API. One of my controller action methods takes two query string parameter, a year and a month.</p>
  
  <p><strong>GET:   /api/ItemsForMonth?year=2019&amp;month=8</strong></p>
  
  <p>The action method looks like this:</p>
  
  <pre><code>[HttpGet]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;Item&gt;&gt;&gt; GetItemsForMonth([FromQuery] int year, [FromQuery] int month)
  {
      if (year &lt;= 2000 || month &lt;= 0 || month &gt; 13)
          return BadRequest("Please check the year and month parameters.");
  }
  </code></pre>
  
  <p>So I am checking to make sure that the year is greater than 2000, and the month is between 1 and 12.</p>
  
  <p>Is that the best way of doing it? I know if the parameters were part of the route instead of query strings (and maybe they should be?) I could do this</p>
  
  <p><strong>GET:   /api/ItemsForMonth/2019/8</strong></p>
  
  <pre><code>[HttpGet("/{year:int:min(2000)}/{month:int:min(1):max(12)}")]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;Item&gt;&gt;&gt; GetItemsForMonth()
  {
  }
  </code></pre>
  
  <p>But is there something similar for query string parameters?</p>
  
  <p>Thanks</p>