title: ASP.NET Core Model Binding from Route and Query String
body: <p>I would like to perform a GET request such as <a href="https://localhost:12345/api/employees/1/calendar/2018/2019?checkHistoricalFlag=true" rel="nofollow noreferrer">https://localhost:12345/api/employees/1/calendar/2018/2019?checkHistoricalFlag=true</a></p>
  
  <p>I have created this method in my controller which works as expected:</p>
  
  <pre><code>[AllowAnonymous]
  [HttpGet("/api/employees/{clockNumber:int}/calendar/{yearFrom:int}/{yearTo:int}")]
  public IActionResult Get(int clockNumber, int yearFrom, int yearTo, bool checkHistoricalFlag = false)
  {
    return Ok();
  }
  </code></pre>
  
  <p>However I would prefer to use the following view model:</p>
  
  <pre><code>public class DetailsQuery
  {
    [Required]
    public int? ClockNumber { get; set; }
    [Required]
    public int? YearFrom { get; set; }
    [Required]
    public int? YearTo { get; set; }
    public bool CheckHistoricalFlag { get; set; } = false;
  }
  </code></pre>
  
  <p>This binds the route parameters but ignores "checkHistoricalFlag" from the query string:</p>
  
  <pre><code>[AllowAnonymous]
  [HttpGet("/api/employees/{clockNumber:int}/calendar/{yearFrom:int}/{yearTo:int}")]
  public IActionResult Get([FromRoute]DetailsQuery query)
  {
    return Ok();
  }
  </code></pre>
  
  <p>Removing [FromRoute] results in a 415 "Unsupported Media Type" error.</p>
  
  <p>Is it possible to bind both the route parameters and query string values to a single view model or do I need to specify the query string values separately?</p>
  
  <pre><code>[AllowAnonymous]
  [HttpGet("/api/employees/{clockNumber:int}/calendar/{yearFrom:int}/{yearTo:int}")]
  public IActionResult Get([FromRoute]DetailsQuery query, bool checkHistoricalFlag = false)
  {
    return Ok();
  }
  </code></pre>