title: File upload with ajax in asp.net mvc
body: <p>I know this has been discussed a lot of times.</p>
  
  <p>I basically want the possibility in my view to update a file. This file has to be mapped to the model the controller expects:</p>
  
  <pre><code>public ActionResult Create(Company company)
  {
      //Do something with the received model
  }
  </code></pre>
  
  <p>The model:</p>
  
  <pre><code>public class Company
  {
      public int Id { get; set; }
      public HttpPostedFileBase PictureUpload { get; set; }
      ...
  }
  </code></pre>
  
  <p>This is working without any problems.
  Now I'd like to send my form data, including the file, via AJAX.
  Therefore I'm using this in my view:</p>
  
  <pre><code>@using (Ajax.BeginForm("Create", "Company", null, new AjaxOptions { HttpMethod = "Post", OnSuccess = "ajaxOnSuccess", OnFailure = "alert('Error message.');" }, new { @class = "ym-form", enctype = "multipart/form-data" }))
  </code></pre>
  
  <p>This is basically working but the file upload doesn't work (as far as I read ajax doesn't have access to the file so it can't be sent).</p>
  
  <p>I'd like what's the best solution for this problem without having to modify my backend (controller/model).</p>
  
  <p>E. g. I read this article:
  <a href="http://ajeeshms.in/Blog/Article/1/upload-files-using-ajax-in-asp-mvc" rel="nofollow">http://ajeeshms.in/Blog/Article/1/upload-files-using-ajax-in-asp-mvc</a></p>
  
  <p>It provides two nice possibilities but I'd have to modify the backend because as far as I see the automatically mapping to the HttpPostedFileBase type in my model wouldn't be possible anymore.</p>
  
  <p>I don't mind using any working plugin for my view or using a technique which is supported by new browsers only.</p>