title: No parameterless constructor defined for this object- Unable to Solve
body: <p>I am new to C# and MVC so please forgive any naiveness/stupidity. I have seen multiple posts dealing with the error I have and I have tried all the solutions but they dont seem to work in my case. Please guide me to the right way to solve this problem.</p>
  
  <p><strong>Background:</strong>
  I have 2 models tblPrograms and tblReports.
  I am trying to build a simple form where the user can create a new tblReport. Part of the process of creating a new tblReport is to select one tblProgram from a list.</p>
  
  <p><strong>Code Overview:</strong></p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>    // GET: /Reports/
  
      public ViewResult New()
      {
  
          ProgramListModel progList = new ProgramListModel();
          tblReports2 report = new tblReports2();
  
          ExistingReportViewModel ervm = new ExistingReportViewModel(report,progList);
  
          return View(ervm);
      }
  
      [HttpPost]
      public ActionResult GenerateSQL(ExistingReportViewModel evrm)
      {
           evrm.Report.ProgramName = evrm.progList.selectedProgram;
          return View(evrm);
      }
  </code></pre>
  
  <p><strong>View Model:</strong></p>
  
  <pre><code> public class ExistingReportViewModel
  {
      public tblReports2 Report { get; set; }       
      public ProgramListModel progList { get; set; }
  
      //public ExistingReportViewModel() { }
      public ExistingReportViewModel(tblReports2 report, ProgramListModel progList)
      {            
          this.Report = report;
          this.progList = progList;   
      }    
  }
  </code></pre>
  
  <p><strong>Models:</strong></p>
  
  <pre><code>public class tblReports2
  {
  
      [Key]
      public string ProgramName { get; set; }
      public string ReportDesc { get; set; }
      ....
  }
  public class ProgramListModel
  {
      public SelectList progList;
      public string selectedProgram;
  
      public ProgramListModel() {
          ReportHelper helper = new ReportHelper();
          this.progList = helper.getProgramList();
      }
  
  }
  </code></pre>
  
  <p><strong>Helper Method:</strong></p>
  
  <pre><code>public SelectList getProgramList()
      {
          var programs = from p in this.DB.tblProgramsSet
                         select p;
          programs = programs.Where(s =&gt; s.ProgramType.Equals("RPT"));                      
          SelectList list = new SelectList(programs, "ProgramName", "ProgramDescription");
          return list;
  
      }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>@model ReportsSetup.Models.ExistingReportViewModel
  
   @{
       ViewBag.Title = "New";
    }
  
    New
   @using (Html.BeginForm("GenerateSQL", "Reports"))
    {
  @Html.ValidationSummary(true)
  &lt;fieldset&gt;
      &lt;legend&gt;ExistingReportViewModel&lt;/legend&gt;
  
          @Html.DropDownListFor(model=&gt;model.progList.selectedProgram, Model.progList.progList)
          &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Report.ReportDesc)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Report.ReportDesc)
          @Html.ValidationMessageFor(model =&gt; model.Report.ReportDesc)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Report.Formerly)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Report.Formerly)
          @Html.ValidationMessageFor(model =&gt; model.Report.Formerly)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Report.ExtendedDesc)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Report.ExtendedDesc)
          @Html.ValidationMessageFor(model =&gt; model.Report.ExtendedDesc)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Report.ReportCode)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Report.ReportCode)
          @Html.ValidationMessageFor(model =&gt; model.Report.ReportCode)
      &lt;/div&gt;
  
     ...
  
          &lt;input type="submit" value="Create" /&gt;
  
  &lt;/fieldset&gt;
  }
  
   &lt;div&gt;
       @Html.ActionLink("Back to List", "Index")
   &lt;/div&gt;
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>![Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.][1]
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/GHJpG.jpg" rel="noreferrer">http://i.stack.imgur.com/GHJpG.jpg</a></p>
  
  <p><strong>Attempted Solutions:</strong></p>
  
  <ol>
  <li><p>Refactored the code to use  IEnumerable &lt;tblPrograms> instead of
  SelectList in ProgramListModel and converting to
  IEnumerable in View using a function similar to
  sample below:</p>
  
  <pre><code>public static IEnumerable&lt;SelectListItem&gt; ToSelectListItems(
            this IEnumerable&lt;Album&gt; albums, int selectedId)
  {
  return 
      albums.OrderBy(album =&gt; album.Name)
            .Select(album =&gt; 
                new SelectListItem
                {
                  Selected = (album.ID == selectedId),
                  Text = album.Name,
                  Value = album.ID.ToString()
                 });
   }
  </code></pre></li>
  <li><p>Refactored the code to use  IEnumerable&lt;SelectListItem> instead of
      SelectList in ProgramListModel</p></li>
  </ol>
  
  <p><strong>Many Thanks in Advance!!</strong></p>