title: How do you post form data and files using Ajax in asp.net.core
body: <p>Using Asp.Net.Core 2.2, Visual Studio 2019</p>
  
  <p>I'd like to get the form data and the files in the same controller action. I've can get the files but not the form data or I can get the form data but not the files. How can I get both?</p>
  
  <p>The return value is some Json that I use to pop up a message and to update the page using Jquery/Javascript.</p>
  
  <p>I thought I had done this in but I can't find any examples in my own code libraries. I've been searching on here and the web and there don't seem to be any examples, which leads me to think (a) its trivial and I'm doing something stupid or (b) its not possible</p>
  
  <p>What am I missing?</p>
  
  <p>My Form</p>
  
  <pre><code>&lt;form asp-controller="Admin" asp-action="EditProduct" id="frmItem" method="post" name="frmItem" novalidate="novalidate" enctype="multipart/form-data"&gt;
  ...
  </code></pre>
  
  <p>My Ajax</p>
  
  <pre><code>$("#uploadFile,#saveUpload").on("click", function (e) {
      e.preventDefault();
  
      var myForm = $("#frmItem");
      var sUrl = myForm.attr("action");
  
      var input = document.getElementById("inputGroupFile02");
      var files = input.files;
      var formData = new FormData();
  
      for (var i = 0; i != files.length; i++) {
          formData.append("importFile", files[i]);
      }
  
      formData.append("item", myForm.serialize());
  
      $.ajax({
          type: "POST",
          url: sUrl,
          contentType: false,
          processData: false,
          data: formData,
          success: function (result) {
              showNotify(result.message);
              hide_modal();
          },
          error: function (err) {
              showNotify("There was an error importing. " + err.statusText + " (" + err.status + ")", "warning", "fa fa-exclamation-triangle");
              hide_modal()
          }
      });
  });
  </code></pre>
  
  <p>My Controller</p>
  
  <pre><code>    [HttpPost]
      //[ValidateAntiForgeryToken]
      public async Task&lt;JsonResult&gt; EditItem(Items item, List&lt;IFormFile&gt; importFile, int id)
  </code></pre>
  
  <p>If I place a break point in the controller and inspect, I can see files (importFile) or I can see data (item) but not both, depending on what method I use</p>