title: Handle file uploads added dynamically in ASP.NET MVC
body: <p>Good day/night, dear SOers,</p>
  
  <p>I stuck with dynamically added file uploads inside the form in ASP.NET MVC.
  I create the form with dynamically added controls (insert rows in the table). One of them is file upload. The controls are added via this jQuery function:</p>
  
  <pre><code>$('#addRow').on('click', function () {
      var counter = $('.itemRow').length;
      $('#itemstable').append('&lt;tr class="itemRow"&gt; &lt;td&gt;&lt;select required name="ItemsList[' + counter + '].ProgramNameShort"&gt;@foreach (SelectListItem item in ViewBag.VBprograms) { &lt;option value="@item.Value"&gt;@item.Text&lt;/option&gt;} &lt;/select&gt;&lt;/td&gt;' +
          '&lt;td&gt;&lt;input type="text" name="ItemsList[' + counter + '].ItemName" /&gt;&lt;/td&gt;' +
          '&lt;td&gt;&lt;input type="text" name="ItemsList[' + counter + '].ItemProducer" /&gt;&lt;/td&gt;' +
          '&lt;td&gt;&lt;input type="text" name="ItemsList[' + counter + '].ItemQty" /&gt;&lt;/td&gt;' +
          '&lt;td&gt;&lt;input type="text" name="ItemsList[' + counter + '].Additional" /&gt;&lt;/td&gt;' +
          '&lt;td&gt;&lt;input type="text" name="ItemsList[' + counter + '].Comments" /&gt;&lt;/td&gt;' + 
          '&lt;td&gt;&lt;input type="file" name="ItemsList[' + counter + '].Image" /&gt;&lt;/td&gt;' +
          '&lt;/tr&gt;');
  
      counter++;
  });
  </code></pre>
  
  <p>My controller receives ViewModel:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Create(CallViewModel callViewModel)
  </code></pre>
  
  <p>ItemsList with Image as <code>[] byte</code> property is the class inside CallViewModel class. Later the object is saved in the database (DB First approach). As far as I understand, images can be uploaded as HttpPostedFileBase object (or IEnumerable  for multiple files uploaded). But how can I handle file uploads uploaded inside such a list?
  I cannot show all the code as it is multi-step multi-tab form with the table being just a part inside one of tabs. If any parts of the code need to be demonstrated I can update current question.</p>
  
  <p>Many thanks in advance.</p>
  
  <p><strong>UPD</strong>
  Here's the relevant part of CallViewModel class:</p>
  
  <pre><code>        public class CallViewModel
              {
      ... //properties used in other tabs
  
           public List&lt;ItemClass&gt; ItemsList { get { return _items; } }
  
           private List&lt;ItemClass&gt; _items = new List&lt;ItemClass&gt;();
  public class ItemClass
          {  //Item
  
              public Guid ItemID { get; set; }
  
              [Required, Display(Name = "Наименование")]
              public string ItemName { get; set; }
  
              [Required, Display(Name = "Производитель")]
              public string ItemProducer { get; set; }
  
              [Required, Display(Name = "Количество")]
              public int ItemQty { get; set; }
  
              [Display(Name = "Комментарии")]
              public string Comments { get; set; }
  
              [Required, Display(Name = "Изображение")]
              public HttpPostedFileBase Image { get; set; }
  
              [Display(Name = "Дополнительно предоставляемые объекты")]
              public string Additional { get; set; }
              //Program
              //[Required, Display(Name = "Полное название")]
              //public string ProgramNameFull { get; set; }
  
              [Required, Display(Name = "Краткое название")]
              public string ProgramNameShort { get; set; }
  
              List&lt;Program&gt; Programs { get; set; }
  }
  }
  </code></pre>