title: ASP.NET core - how to pass optional [FromBody] parameter?
body: <p>How do I pass optional (nullable) [FromBody] parameter in ASP.NET Core (5.0)? If I don't send body in my request I get 415 Unsupported Media Type error. Can this be configured and if so, how to do it on a controller or action, rather than an app level? I presume it has to do something with model validation, but not sure. Thanks.</p>
  <pre><code>[HttpGet(&quot;[action]&quot;)]
  public async Task&lt;IActionResult&gt; GetElementsAsync([FromBody] IEnumerable&lt;int&gt; elements = default)
  {
    var result = await dataService.GetData(elements);
    return Ok(result);
  }
  </code></pre>
  <p><strong>EDIT: To clarify:</strong></p>
  <p>This is typical scenario and it works normally:
  <a href="https://i.stack.imgur.com/5LcE5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5LcE5.png" alt="This is typical scenario and it works normally" /></a></p>
  <p>But passing empty body is returning 415 right away without even reaching action:
  <a href="https://i.stack.imgur.com/sMD1j.png" rel="noreferrer"><img src="https://i.stack.imgur.com/sMD1j.png" alt="Passing empty body is returning 415 right away without reaching action" /></a></p>