title: asp.net core - modelstate badrequest inconsistent behaviour
body: <p>I have a simple model:</p>
  
  <pre><code>public class Item : Entity&lt;int&gt;
  {
      [Required]
      public string Name { get; set; }
      [Required]
      public int Cost { get; set; }
  }
  </code></pre>
  
  <p>Inside controller:</p>
  
  <pre><code>[HttpPost]
  public async Task&lt;IActionResult&gt; Create([FromBody] Item item)
  {
      if(!ModelState.IsValid) 
      {
         return BadRequest(ModelState);
      }
      repository.Create(item);
      await repository.SaveAsync();
      return Created($"/api/v1/items/{item.Id}", new { message = "Item was created successfully!" });
  }
  </code></pre>
  
  <p>Now, for following three incorrect sample inputs I get following responses:</p>
  
  <p>Sample #1:</p>
  
  <pre><code>POST http://localhost:5000/api/v1/items
  content-type: application/json
  
  {
      "name": "sample1",
      "cost": $100000
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>{
    "cost": [
      "The input was not valid."
    ]
  }
  </code></pre>
  
  <p>Sample #2:</p>
  
  <pre><code>POST http://localhost:5000/api/v1/items
  content-type: application/json
  
  {
      "name": "sample2",
      "cost": "10000000000000000000000000"
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>{
    "cost": [
      "The input was not valid."
    ]
  }
  </code></pre>
  
  <p>Sample #3:  <strong>This one seems like a bug. An empty key appears (instead of int out of range error)</strong></p>
  
  <pre><code>POST http://localhost:5000/api/v1/items
  content-type: application/json
  
  {
      "name": "sample3",
      "cost": 10000000000000000000000000
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>{
    "": [
      "The input was not valid."
    ],
    "cost": [
      "The input was not valid."
    ]
  }
  </code></pre>
  
  <p><strong>Edit:</strong>
  Added a tracking ticket on github - <a href="https://github.com/aspnet/Mvc/issues/5672" rel="nofollow noreferrer">https://github.com/aspnet/Mvc/issues/5672</a></p>