title: Uploading File using Ajax in Asp.Net Core
body: <p>Good day everyone,</p>
  
  <p>I'm trying to upload file using ajax from client side to server side (asp.net core) controller but I'm having a null value.</p>
  
  <p>Here's my html and javascript codes:</p>
  
  <pre><code>&lt;input type="file" id="myfile" class="required" /&gt;
  &lt;button type="button" class="btn btn-info" onclick="uploadcsvfile()"&gt;
  
  &lt;script&gt;
      function uploadcsvfile() {
         var myfile= document.getElementById("myfile");
         var formData = new FormData();
  
         if (myfile.files.length &gt; 0) {
             for (var i = 0; i &lt; myfile.files.length; i++) {
                 formData.append('file-' + i, myfile.files[i]);
             }
         }
  
         $.ajax({
             url: "/MyController/UploadFile/",
             type: "POST",
             dataType: "json",
             data: formData,
             contentType: false,
             processData: false,
             success: function(data){
  
             },
             error: function (data) {
  
             }
          })
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Here's my controller that uses IFormFile</p>
  
  <pre><code>public async Task&lt;JsonResult&gt; UploadFile(IFormFile formData)
  {
        // do something here
  }
  </code></pre>
  
  <p>Thank you in advance!</p>