title: Default model binding throwing "No paramaterless constructor defined for this object"
body: <p>I have a form where we want to enter multiple deals for a single customer. The viewmodel for the form looks like this:</p>
  
  <pre><code>public class TradeSpendingEntryViewModel
  {
      public TradeSpendingEntryViewModel()
      {
          Records = new List&lt;TradeSpendingEntryViewModelRecord&gt;();
      }
  
      public string CustomerNumber { get; set; }
      public DateTime Date { get; set; }
      public SelectList PlanningYears { get; set; }
  
      public List&lt;TradeSpendingEntryViewModelRecord&gt; Records { get; set; }
  }
  </code></pre>
  
  <p>We want to be able to add and remove record entry rows dynamically with javascript. Each record in the collection is:</p>
  
  <pre><code>public class TradeSpendingEntryViewModelRecord
  {
      public TradeSpendingEntryViewModelRecord()
      {
      }
  
      public string LOB { get; set; }
      public string ProductCode { get; set; }
      public SelectList AllowType { get; set; }
      public int Cases { get; set; }
      public bool EndCurrentDeal { get; set; }
      public Single DealRate { get; set; }
      public DateTime StartDate { get; set; }
      public DateTime EndDate { get; set; }
      public string Comments { get; set; }
  }
  </code></pre>
  
  <p>When I attempt to post data to my controller, I get an error indicating "No parameterless constructor defined for this object:</p>
  
  <pre><code>[HttpPost]
      public ActionResult Index(TradeSpendingEntryViewModel vm)
      {
          try
          {
              if (ModelState.IsValid)
              {
                  return RedirectToAction("Index");
              }
              // TODO: Add insert logic here
              return View(vm);
          }
          catch
          {
              return View();
          }
      }
  </code></pre>
  
  <p>Stack trace indicates it happens during the model binding:</p>
  
  <blockquote>
    <p>[MissingMethodException: No parameterless constructor defined for this object.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +113
       System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +232
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
       System.Activator.CreateInstance(Type type) +6
       System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +183</p>
  </blockquote>
  
  <p>My issue must be stemming from how I've setup my view, the markup of which I have based off this article <a href="http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx" rel="noreferrer">http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx</a></p>
  
  <pre><code>@using (Html.BeginForm())
  {
  &lt;header class="clearfix"&gt;
          &lt;img src="../../Content/images/logo.png" alt="Irving Consumer Products" /&gt;
          &lt;h1&gt;Enter Customer Deals&lt;/h1&gt;
      &lt;/header&gt;
      &lt;hr /&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;Customer details&lt;/legend&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Date:
                  &lt;/th&gt;
                  &lt;td&gt;
                      &lt;input type="date" disabled="disabled" value="@DateTime.Today.ToShortDateString()" /&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Customer Number:
                  &lt;/th&gt;
                  &lt;td&gt;
                      @Html.TextBoxFor(m =&gt; m.CustomerNumber, new { id = "customer-number" })
                      &lt;a href="#" id="change-customer-number"&gt;Change me&lt;/a&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Customer Name:
                  &lt;/th&gt;
                  &lt;td&gt;
                      &lt;input type="text" id="customer-name" disabled="disabled" /&gt;
                  &lt;/td&gt;
                  &lt;tr&gt;
                      &lt;th&gt;
                          Planning Year:
                      &lt;/th&gt;
                      &lt;td&gt;
                          @Html.DropDownList("PlanningYear", Model.PlanningYears)
                          &lt;a href="#" id="change-planning-year"&gt;Change me&lt;/a&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/fieldset&gt;
      &lt;div class="buttonGroup"&gt;
          &lt;input type="button" value="Add line" id="add-line"&gt;
          &lt;input type="button" value="Copy line" id="copy-line"&gt;
          &lt;input type="button" value="Delete line" id="delete-line"&gt;
      &lt;/div&gt;
      &lt;hr /&gt;
      &lt;table id="tradeSpendingEntry"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                  &lt;/th&gt;
                  &lt;th&gt;
                      Line of business
                  &lt;/th&gt;
                  &lt;th&gt;
                      Product Code
                  &lt;/th&gt;
                  &lt;th&gt;
                      Product Description
                  &lt;/th&gt;
                  &lt;th&gt;
                      Allowance
                      &lt;br /&gt;
                      Type
                  &lt;/th&gt;
                  &lt;th&gt;
                      Cases
                  &lt;/th&gt;
                  &lt;th&gt;
                      End Current Deal
                  &lt;/th&gt;
                  &lt;th&gt;
                      Start Date
                  &lt;/th&gt;
                  &lt;th&gt;
                      End Date
                  &lt;/th&gt;
                  &lt;th&gt;
                      Rate
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          @foreach (var r in Model.Records)
          {
              &lt;tbody data-entry-index="0"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;input type="checkbox" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="text" name="records[0].LOB" class="lobSelect" value="@r.LOB"&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;!--&lt;input type="hidden" name="records[0]ProductCodeSelected" value="@r.ProductCode" /&gt;--&gt;
                      &lt;input type="text" name="records[0].ProductCode" value="@r.ProductCode"&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="text" class="product-description" disabled="disabled" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DropDownList("records[0].AllowType", r.AllowType)
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input name="records[0].Cases" type="number" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;select name="records[0].EndCurrentDeal"&gt;
                          &lt;option value="true" selected="selected"&gt;Yes&lt;/option&gt;
                          &lt;option value="false"&gt;No&lt;/option&gt;
                      &lt;/select&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="date" name="records[0].StartDate" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="date" name="records[0].EndDate" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="text" name="records[0].DealRate" /&gt;
                  &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;
                      Comments:
                  &lt;/td&gt;
                  &lt;td colspan="8"&gt;
                      &lt;input type="text" class="comment" name="records[0].Comments" /&gt;
                  &lt;/td&gt;
                  &lt;/tr&gt;
          &lt;/tbody&gt;
          }
      &lt;/table&gt;
  
      &lt;footer&gt;
          &lt;div class="buttonGroup"&gt;
          &lt;input type="submit" value="Submit Changes"&gt;
          &lt;input type="button" value="Main Menu"&gt;
          &lt;input type="button" value="View Customer Deals"&gt;
      &lt;/div&gt;
      &lt;/footer&gt;
      }
  </code></pre>
  
  <p>So, my hope was that the fields in the first fieldset would map to the immediate properties of the TradeSpendingEntryViewModel object (CustomerName, Date, PlanningYears). Then, for each  representing a TradeSpendingEntryViewModelRecord would be bound as an item in the TradeSpendingEntryViewModel.Records collection. Instead, I just get a mysterious "No parameterless constructor defined" exception, despite both the ViewModel and the record object both having paramaterless constructors.</p>
  
  <p>My question is, can I use the default model binder using the conventions indicated in the aforementioned article, or do I need to build a custom model binder for this purpose?</p>
  
  <p>For completeness sake, the following is the markup of the form that gets generated after a user dynamically adds a line to the form via javascript:</p>
  
  <pre><code>&lt;form method="post" action="/TradeSpendingEntry/Index"&gt;
  &lt;header class="clearfix"&gt;
  &lt;img alt="Irving Consumer Products" src="../../Content/images/logo.png"&gt;
  &lt;h1&gt;Enter Customer Deals&lt;/h1&gt;
  &lt;/header&gt;
  &lt;hr&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Customer details&lt;/legend&gt;
  &lt;table&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;th&gt; Date: &lt;/th&gt;
  &lt;td&gt;
  &lt;input id="dp1363608756704" class="hasDatepicker" type="date" value="18/03/2013" disabled="disabled" style="background-color: rgb(238, 238, 238);"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;th&gt; Customer Number: &lt;/th&gt;
  &lt;td&gt;
  &lt;input id="customer-number" type="text" value="" name="CustomerNumber"&gt;
  &lt;a id="change-customer-number" href="#"&gt;Change me&lt;/a&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;th&gt; Customer Name: &lt;/th&gt;
  &lt;td&gt;
  &lt;input id="customer-name" type="text" disabled="disabled" style="background-color: rgb(238, 238, 238);"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;th&gt; Planning Year: &lt;/th&gt;
  &lt;td&gt;
  &lt;select id="PlanningYears" name="PlanningYears"&gt;
  &lt;option value="2011"&gt;2011&lt;/option&gt;
  &lt;option value="2012"&gt;2012&lt;/option&gt;
  &lt;option value="2013"&gt;2013&lt;/option&gt;
  &lt;option value="2014"&gt;2014&lt;/option&gt;
  &lt;/select&gt;
  &lt;a id="change-planning-year" href="#"&gt;Change me&lt;/a&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/fieldset&gt;
  &lt;div class="buttonGroup"&gt;
  &lt;input id="add-line" type="button" value="Add line"&gt;
  &lt;input id="copy-line" type="button" value="Copy line"&gt;
  &lt;input id="delete-line" type="button" value="Delete line"&gt;
  &lt;/div&gt;
  &lt;hr&gt;
  &lt;table id="tradeSpendingEntry"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
  &lt;th&gt; &lt;/th&gt;
  &lt;th&gt; Line of business &lt;/th&gt;
  &lt;th&gt; Product Code &lt;/th&gt;
  &lt;th&gt; Product Description &lt;/th&gt;
  &lt;th&gt;
  Allowance
  &lt;br&gt;
  Type
  &lt;/th&gt;
  &lt;th&gt; Cases &lt;/th&gt;
  &lt;th&gt; End Current Deal &lt;/th&gt;
  &lt;th&gt; Start Date &lt;/th&gt;
  &lt;th&gt; End Date &lt;/th&gt;
  &lt;th&gt; Rate &lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody data-entry-index="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;input type="checkbox"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input class="lobSelect" type="text" name="records[0].LOB"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input type="text" name="records[0].ProductCode"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input class="product-description" type="text" disabled="disabled" style="background-color: rgb(238, 238, 238);"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;select id="records_0__AllowType" name="records[0].AllowType"&gt;
  &lt;option selected="selected"&gt;BillBack$&lt;/option&gt;
  &lt;option&gt;Billback%&lt;/option&gt;
  &lt;option&gt;O&amp;A%&lt;/option&gt;
  &lt;option&gt;Coop%&lt;/option&gt;
  &lt;option&gt;VR%&lt;/option&gt;
  &lt;option&gt;Lump - O&amp;A$&lt;/option&gt;
  &lt;option&gt;Lump - CP$&lt;/option&gt;
  &lt;option&gt;Lump - VR$&lt;/option&gt;
  &lt;option&gt;Lump - BB$&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input type="number" name="records[0].Cases"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;select name="records[0].EndCurrentDeal"&gt;
  &lt;option selected="selected" value="true"&gt;Yes&lt;/option&gt;
  &lt;option value="false"&gt;No&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input id="dp1363608756707" class="hasDatepicker" type="date" name="records[0].StartDate"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input id="dp1363608756708" class="hasDatepicker" type="date" name="records[0].EndDate"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input type="text" name="records[0].DealRate"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt; Comments: &lt;/td&gt;
  &lt;td colspan="8"&gt;
  &lt;input class="comment" type="text" name="records[0].Comments"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tbody data-entry-index="1"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;input type="checkbox"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input class="lobSelect" type="text" name="records[1].LOB"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input type="text" name="records[1].ProductCode"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input class="product-description" type="text" disabled="disabled" style="background-color: rgb(238, 238, 238);"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;select id="records_0__AllowType" name="records[1].AllowType"&gt;
  &lt;option selected="selected"&gt;BillBack$&lt;/option&gt;
  &lt;option&gt;Billback%&lt;/option&gt;
  &lt;option&gt;O&amp;A%&lt;/option&gt;
  &lt;option&gt;Coop%&lt;/option&gt;
  &lt;option&gt;VR%&lt;/option&gt;
  &lt;option&gt;Lump - O&amp;A$&lt;/option&gt;
  &lt;option&gt;Lump - CP$&lt;/option&gt;
  &lt;option&gt;Lump - VR$&lt;/option&gt;
  &lt;option&gt;Lump - BB$&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input type="number" name="records[1].Cases"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;select name="records[1].EndCurrentDeal"&gt;
  &lt;option selected="selected" value="true"&gt;Yes&lt;/option&gt;
  &lt;option value="false"&gt;No&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input id="dp1363608756709" class="hasDatepicker" type="date" name="records[1].StartDate"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input id="dp1363608756710" class="hasDatepicker" type="date" name="records[1].EndDate"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input type="text" name="records[1].DealRate"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt; Comments: &lt;/td&gt;
  &lt;td colspan="8"&gt;
  &lt;input class="comment" type="text" name="records[1].Comments"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;footer&gt;
  &lt;div class="buttonGroup"&gt;
  &lt;input type="submit" value="Submit Changes"&gt;
  &lt;input type="button" value="Main Menu"&gt;
  &lt;input type="button" value="View Customer Deals"&gt;
  &lt;/div&gt;
  &lt;/footer&gt;
  &lt;/form&gt;
  </code></pre>