title: How to PATCH a value to be null with model binding
body: <p>If I have an object like this</p>
  
  <pre><code>public class Movie
  {
      public long Id { get; set; }
      public string Name { get; set; }
      public long? Length { get; set; }
      ...
  }
  </code></pre>
  
  <p>and have a controller to update its values:</p>
  
  <pre><code>    [HttpPatch("{id}")]
      public IActionResult Patch(long id, [FromBody] Movie item)
      {
  
          Movie movie  = (....
  
          if (item.Length.HasValue)
          {
              movie.Length = item.Length;
              _context.Entry&lt;Movie&gt;(movie).Property(w =&gt; w.Length).IsModified = true;
          }
  
          if (item.Name.HasValue)
          {
              movie.Name = item.Length;
              _context.Entry&lt;Movie&gt;(movie).Property(w =&gt; w.Name).IsModified = true;
          }
      }
  </code></pre>
  
  <p>It works when a Length is supplied, but what if I want to update it to be undefined (null)?
  If the value is deleted in the front end, the PATCH data is: </p>
  
  <pre><code>{"length":""}
  </code></pre>
  
  <p>At the controller, the model binding interprets this as null.</p>
  
  <p>So this:</p>
  
  <pre><code>if (item.Length.HasValue)
  </code></pre>
  
  <p>cause it to do nothing.</p>
  
  <p>For a moment I considered removing the if condition, because then it would update it to null if an empty string was passed, but of course, if any other property such as Name is patched, the Length would also be set to null which would be bad.
  The problem is that there is no way (that I can see) in the controller to determine that Length was PATCHED but is null</p>