title: HttpPostedFileBase not binding to model C# MVC 5
body: <p>I am trying to upload attachments for an email message that will be sent from my site. I'm using an input tag of type file with the multiple keyword specified, and ajax to send the file(s) and other model properties back to the controller.</p>
  
  <p>However, all the model properties are bound once the controller is reached, with the exception of the property to contain the files.</p>
  
  <p>The uploaded file(s) are present when the request is inspected with fiddler and they are also present in the Request.Files collection on the controller.</p>
  
  <p>Should my files be automatically bound to the model using this method, or do I have to write a custom binder to accomplish this?</p>
  
  <p>[Non relevant code has been removed]</p>
  
  <p><strong>This is the object that should contain the files</strong></p>
  
  <pre><code>public class Attachment
  {        
      public IEnumerable&lt;HttpPostedFileBase&gt; Files { get; set; }
  
      public Attachment()
      {
          Files = new List&lt;HttpPostedFileBase&gt;();
      }    
  }
  </code></pre>
  
  <p><strong>This is the object that contains the attachments and the other model properties</strong></p>
  
  <pre><code>public class QuoteRequest
  {      
      public Attachment Attachment { get; set; }
  
      public QuoteRequest()
      {            
          Attachment = new Attachment();
      }
  }
  </code></pre>
  
  <p><strong>The view the user will use to upload has the following form</strong></p>
  
  <pre><code>@using (Html.BeginForm("Index", "Quote", FormMethod.Post, new { required = "true", id = "frm-quote", enctype = "multipart/form-data" })) {
  @Html.AntiForgeryToken()
  
  @Html.EditorFor(model =&gt; model.Contact, "ContactForm")
  
  @Html.EditorFor(model =&gt; model.Enquiry, "EnquiryForm")
  
  @Html.EditorFor(model =&gt; model.Attachment, "AttachmentForm")
  
  &lt;div class="row"&gt;
      &lt;div class="col l10 offset-l2 m6 s12 add-pad-bot center"&gt;
          &lt;button class="col s12 btn waves-effect orange" type="reset" data-test-clear&gt;CLEAR&lt;/button&gt;
      &lt;/div&gt;
  
      &lt;div class="col l10 offset-l2 m6 s12 center"&gt;
          &lt;button class="col s12 btn waves-effect waves-green green" type="button" data-test-submit&gt;SUBMIT&lt;/button&gt;
      &lt;/div&gt;
  &lt;/div&gt;  }
  </code></pre>
  
  <p><strong>This is the partial view that deals with the file input tag</strong></p>
  
  <pre><code>@using Domain.Models
  
  @model Attachment
  
  &lt;section id="attachment" class="row no-mar-bot"&gt;
  
      &lt;div class="file-field input-field col s12"&gt;
          &lt;div class="btn primary"&gt;
              &lt;span id="icon-attachment"&gt;
                  &lt;i class="medium material-icons"&gt;note_add&lt;/i&gt;
              &lt;/span&gt;
              @Html.TextBoxFor(m =&gt; m.Files, new {type = "file", multiple = 
  "multiple"})
          &lt;/div&gt;
          &lt;div class="file-path-wrapper"&gt;
              &lt;input class="file-path validate" type="text" placeholder="Upload one or more files"&gt;
          &lt;/div&gt;                
      &lt;/div&gt;
  
  &lt;/section&gt;
  </code></pre>
  
  <p><strong>The javascript function that gets the form inputs to post to the controller</strong></p>
  
  <pre><code>function getFormData() {
  
  var formData;
  
  formData = new FormData();
  
  var fileUpload = $("#Attachment_Files").get(0);
  var files = fileUpload.files;
  
  if (files) {
      // Looping over all files and add it to FormData object  
      for (var i = 0; i &lt; files.length; i++) {
          console.log("files[i].name:" + files[i].name);
          formData.append(files[i].name, files[i]);
      }
  }
  
  // You can update the jquery selector to use a css class if you want
  $("input:not([type='file']), textarea").each(function (x, y) {
      formData.append($(y).attr("name"), $(y).val());
  });
  
  return formData; }
  </code></pre>
  
  <p><strong>The code for the ajax post</strong></p>
  
  <pre><code>$.ajax({
      url: "/quote",
      method: "POST",
      cache: false,
      contentType: false,
      processData: false,
      data: getFormData()
      headers: {
          '__RequestVerificationToken': 
          $("input[name='__RequestVerificationToken']").val()
        }
   })
  .fail(function(jqXHR, textStatus) { })
  .done(function(data) { });
  </code></pre>
  
  <p><strong>This is the controller action method that receives the post</strong></p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryHeader]
  [Route("")]
  public ActionResult Index(QuoteRequest model) { }
  </code></pre>