title: ASP.NET Core route never executed when using [FromBody] viewModel, but it works if using [FormBody] object?
body: <p>I would like to send post, patch request to my backend server. I am sending the request with angular and I am attaching the object to be updated in the request body like this:</p>
  
  <pre><code>`
      return this.http
            .patch&lt;GearItem&gt;(
              `${this.merchandiseUrl}/${gearItem.id}`,
              JSON.stringify(gearItem),
              this.headers
            )
  `
  </code></pre>
  
  <p>On the back-end I have the following route:</p>
  
  <pre><code>`
  [HttpPatch("{id}")]
      public async Task&lt;IActionResult&gt; Update([FromBody] GearItemViewModel gearItem)
      {
  
        return Ok();
      }
  `
  </code></pre>
  
  <p>This route never gets executed, however when I change it to:</p>
  
  <pre><code>[HttpPatch("{id}")]
      public async Task&lt;IActionResult&gt; Update([FromBody] object gearItem)
      {
  
        return Ok();
      }
  </code></pre>
  
  <p>The route gets hit and gets executed.</p>
  
  <p>The structure of the object that I am sending from angular is like this:</p>
  
  <pre><code>`
  formData: FormData {}
  id: 3
  images: (3) [{…}, {…}, {…}]
  inStock: true
  name: "Hat"
  price: 27
  sizes: (6) [{…}, {…}, {…}, {…}, {…}, {…}]
  `
  </code></pre>
  
  <p>And the GearItemViewModel is as follow:</p>
  
  <pre><code>public class GearItemViewModel
    {
      public long Id { get; set; }
      public string Name { get; set; }
      public decimal Price { get; set; }
      public bool InStock { get; set; }
      public string FormData { get; set; }
      public IEnumerable&lt;GearSizeViewModel&gt; Sizes { get; set; }
      public IEnumerable&lt;GearImageViewModel&gt; Images { get; set; }
    }
  </code></pre>
  
  <p>I'm not sure why I am not able to retrieve the viewModel object via the Update method arguments using the [FromBody] attribute. In the logs I see something about <code>Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'.</code> But I dont know why there is a validation problem when the models from the backend and front end have all the same property names.</p>