title: Upload image with ajax, HttpPostedFileBase is null Mvc Asp
body: <p>I must upload image before Form is submitted. So I used ajax to do it.</p>
  
  <p>Here is my HelpController:</p>
  
  <pre><code>[HttpPost]
  public void AcceptUpload(HttpPostedFileBase TemporaryForLast, string ReferanceNo)
  {
      TemporaryForLast.SaveAs(Server.MapPath("~/Profiles/images/" + ReferanceNo + "/") + "HoldCopy" + ".jpg");
  }
  </code></pre>
  
  <p>Here is my view:</p>
  
  <pre><code>&lt;input id="HoldCopy" type="file" name="HoldCopy" accept="image/*"&gt;
  </code></pre>
  
  <p>Ans Script:</p>
  
  <pre><code>$("#acceptUpload").click(function () {
      var formData= new FormData();
      var imagefile=document.getElementById("HoldCopy").files[0];
      formData.append("imageFile",imageFile);
      var xhr = new XMLHttpRequest();
      xhr.open("POST", "/Help/AcceptUpload", true);
      xhr.addEventListener("load", function (evt) { UploadComplete(evt); }, false);
      xhr.addEventListener("error", function (evt) { UploadFailed(evt); }, false);
      xhr.send(formData);
  });
  </code></pre>
  
  <p><code>error</code> functions are also updated.</p>