title: File upload bound to the Viewmodel
body: <p>I have a form where I am uploading multiple files and there are a couple of textboxes and some checkboxes associated with each file being uploaded.
  I have seen examples for uploading multiple files where the actionresult signature is something like this:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Upload(IEnumerable&lt;HttpPostedFileBase&gt; fileUpload)
  </code></pre>
  
  <p>However, I cant find any example where I can have multiple files uploaded where my actionresult signature is something like this: </p>
  
  <pre><code>[HttpPost]
  public ActionResult Upload(MyViewModel vm)
  </code></pre>
  
  <p>The reason I want this viewmodel being posted is because I think its cleaner than using the FormCollection variable and because I want to each file being uploaded and the data added along with its associated textboxes to be grouped together by way of a <code>List&lt;FileUploadPacket&gt;</code> which will part of the ViewModel</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My View model below:</p>
  
  <pre><code>public class EmployeeVM  
  {
  
      public int EmployeeID {get ;set;}
      public string EmpName {get ;set;}
      //Other properties
  
      public List&lt;FileUploadPacket&gt; FileUploadPackets { get; set; }
  }
  </code></pre>
  
  <p>The FileUploadPacket class which has the property of type HttpPostedFileBase</p>
  
  <pre><code>public class FileUploadPacket 
  {
  
      public int FileID {get ;set;}
      public string UserEnteredDesc {get ;set;}
      //some more other properties
  
      public HttpPostedFileBase UpFile { get; set; }
  }
  </code></pre>
  
  <p>Code snippet of my view.aspx as below</p>
  
  <pre><code>&lt;%: Html.TextBoxFor(model =&gt; model.EmpName, new { maxLength = 50 })%&gt;
  
  Upload your files here: 
  &lt;input type="file" id="UpFile" name="UpFile" value="ActionHandlerForForm"  /&gt;
  &lt;%: Html.TextBoxFor(model =&gt; model.FileUploadPackets[0].UserEnteredDesc )%&gt;
  
  &lt;input type="file" id="UpFile" name="UpFile" value="ActionHandlerForForm"  /&gt;
  &lt;%: Html.TextBoxFor(model =&gt; model.FileUploadPackets[1].UserEnteredDesc )%&gt;
  </code></pre>
  
  <p>As you can see, I have all the other properties specific to this one file being uploaded kept in its own class. So that in my form an employee can enter his name and upload his files and provide some description and other details for each file. If I move the public <code>HttpPostedFileBase UpFile { get; set; }</code> property to the <code>EmployeeVM</code> class then I will have to collect all the files separately in an array and manually map a file to its description. Is there no way to do this keeping the <code>UpFile</code> property in the <code>FileUploadPacket</code> class itself?</p>
  
  <p>I am using the aspx view engine. </p>
  
  <p>Please help. Thanks for your time...</p>