title: How do I allow empty value to be passed to MVC WebApi for a double type
body: <p>I have a simple WebApi 2.1 project and am receiving a model state error when I post and leave the value for a non-required nullable field (double type) blank. I want to leave the xml element  but allow it to be blank. I had assumed making the field nullable would handle this but instead, if I post with salary left blank, I receive the error (listed below). If I put a number in... such as <code>&lt;salary&gt;32000&lt;/salary&gt;</code> everything works as expected.</p>
  
  <p>How can I allow a blank value for a nullable double and still pass model validation?</p>
  
  <p><strong>The error I receive:</strong> </p>
  
  <blockquote>
    <p>System.Web.Http.ModelBinding.ModelError: "There is an error in XML
    document (1, 111)."</p>
  </blockquote>
  
  <p><strong>My Model:</strong></p>
  
  <pre><code>public class Employee
  {
      [Required]
      public string LastName { get; set; }
  
      public string MiddleName { get; set; }
  
      [Required]
      public string FirstName { get; set; }
  
      public double? Salary { get; set; }
  }
  </code></pre>
  
  <p><strong>My Controller Post Method:</strong></p>
  
  <pre><code>public HttpResponseMessage Post([FromBody]Employee employee)
  {
      if (ModelState.IsValid)
      {
          string firstName = employee.FirstName;
          string lastName = employee.LastName;
  
          if (employee.Salary != null)
          {
              double? salary = employee.Salary;
          }
  
          return Request.CreateResponse(HttpStatusCode.OK);
      }
      else
      {
          return Request.CreateErrorResponse(HttpStatusCode.NoContent, ModelState);
      }
  }
  </code></pre>
  
  <p><strong>Here is my actual Post (with headers listed):</strong></p>
  
  <pre><code>Content-Type: application/xml
  Accept-Language: en-us
  Accept: application/xml
  
  &lt;Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;LastName&gt;Charlie&lt;/LastName&gt;
      &lt;MiddleName&gt;Bravo&lt;/MiddleName&gt;
      &lt;FirstName&gt;Alpha&lt;/FirstName&gt;
      &lt;Salary&gt;&lt;/Salary&gt;
  &lt;/Employee&gt;
  </code></pre>