title: "400 bad request" when posting data to asp.net core web api with FormData in XmlHttpRequest
body: <p>I have a ASP.Net Core web API with this action :</p>
  
  <pre><code>    // POST api/TodoList
      [HttpPost]
      public void Post([FromBody] Tache tache)
      {
         TodoListContext.AjouterTache(tache);
      }
  </code></pre>
  
  <p>Here is the code of the Tache entity :</p>
  
  <pre><code>    public class Tache
      {
         public int Id { get; set; }
  
         [DataType(DataType.MultilineText)]
         [Required, MaxLength(250)]
         public string Description { get; set; }
  
         [DataType(DataType.Date)]
         public DateTime DateCreation { get; set; }
  
         [DataType(DataType.Date)]
         public DateTime DateEcheance { get; set; }
  
         public int Priorite { get; set; }
  
         public bool Terminee { get; set; }
      }
  </code></pre>
  
  <p>I call the action from  a javascript SPA, with XHR like this :</p>
  
  <pre><code>    function ajouterTache() {
         // Construit un objet Tâche à partir des valeurs saisies
         let tache = {}; 
         tache.id = document.getElementById("idTache").value;
         tache.dateCreation = document.getElementById("dateCreation").value;
         tache.dateEcheance = document.getElementById("dateEcheance").value;
         tache.priorite = document.getElementById("priorite").value;
         tache.terminee = document.getElementById("terminee").checked;
         tache.description = document.getElementById("description").value; 
         console.log(tache);
  
         // Envoie la tâche à l'API
         const req = new XMLHttpRequest();
         req.onload = function () {
            ...
         };
  
         req.open('POST', uri, true);
         req.setRequestHeader("Content-Type", "application/json");
         req.send(JSON.stringify(tache));
      }
  </code></pre>
  
  <p>The code above works fine, but this one does not :</p>
  
  <pre><code>    function ajouterTache() {
         data = new FormData(document.getElementById("formEdit"));
  
         // Envoie la tâche à l'API
         const req = new XMLHttpRequest();
         req.onload = function () {
          ...
         };
  
         req.open('POST', uri, true);
         req.setRequestHeader("Content-Type", "application/json");
         req.send(data);
      }
  </code></pre>
  
  <p>Each field of the form has a correct name, is enabled and contains valid  input.</p>
  
  <p>But I always get à "400 : bad request" response.<br/>
  Debug tools of Firefox show the following error in the XHR result :</p>
  
  <blockquote>
    <p>Input string '-----------------------------18691991225667' is not a valid number. Path '', line 1, position 43.<br/>
    title : One or more validation errors occurred</p>
  </blockquote>
  
  <p>I added this code before sending the xhr to watch the content of the data object :</p>
  
  <pre><code>    let formData = new FormData(document.getElementById("formEdit"));
      for (let pair of formData.entries()) {
         console.log(pair[0] + ': ' + pair[1] + ", " + typeof pair[1]);
      }
  </code></pre>
  
  <p>Here is the result :</p>
  
  <pre><code>idTache: 11
  dateCreation: 2019-10-08
  dateEcheance: 2019-10-22
  priorite: 1
  terminee: on
  description: essai
  </code></pre>
  
  <p>It seems to be correct. So what is wrong with my using of FormData ?</p>