title: MVC asp.net PartialView causing No Parameterless constructor error?
body: <p>Having an issue with an MVC 2.0 application partial view that all of the sudden when accessed and stuff is actually in the ViewData, the dreaded No parameterless Constructor error. I Have followed the code as much as I can and I'm getting no where. Here is my code:</p>
  
  <p>Controller:</p>
  
  <pre><code>  using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      using System.ComponentModel;
      using CINet.Areas.CatalystSearch.Models.Interfaces;
      using CINet.Areas.CatalystSearch.Models.Repository;
      using CINet.Areas.CatalystSearch.Models.Entities;
  
      namespace CINet.Areas.CatalystSearch.Controllers
      {
          public class CatalystSearchController : Controller
          {
             // private SqlCatalystRepository _catalystItemRepository;
              private ICatalystRepository _catalystInterface;
              public int PageSize = 10; // Regulates size of page
  
          #region CONSTRUCTOR
  
          /// &lt;summary&gt;
          /// Constructor which sets the passed repository to the local current 
          /// repository
          /// &lt;/summary&gt;
          /// &lt;param name="catalystRepository"&gt;Interface repository for controller&lt;/param&gt;
          public CatalystSearchController()
          {
  
          }
  
          #endregion
  
          #region  DEFAULT VIEW
  
  
          public ViewResult List([DefaultValue("")] string manufactureName, [DefaultValue("")] string manufacturePartNumber, [DefaultValue("")] string description, [DefaultValue(1)] int page)
          {
  
              IQueryable&lt;CatalystItem&gt; query = null;
              CatalystFilter userFilter = new CatalystFilter();
              int totalItems = 0;
  
             // Be sure that the manufacture drop down has been selected
              if (manufactureName != "")
              {
                  // Set up CatalystFilter
                  userFilter.Manufacture = manufactureName;
                 userFilter.DescriptionFilter = description;
                  userFilter.ManufacturePartNumberFilter = manufacturePartNumber;
  
                  // connection string for SQL
                  string connString = "Data Source=se-cinet-dev;Initial Catalog=cinet;User ID=sa;Password=Carouse1";
  
  
                  // Get interface
                  _catalystInterface = new CatalystRepository(connString);
  
  
                  // Collects data from SQL repository and updates private local copy
                 // _catalystItemRepository = new SqlCatalystRepository(connString);
  
                  // Fills with list of Catalystitems based on filter.
                  query = _catalystInterface.GetCatalystItems(userFilter, page, PageSize);
                  // query = _catalystItemRepository.GetItems(userFilter, page, PageSize);
  
                  // Returns int of total items in list
                  totalItems = _catalystInterface.GetTotalOfItems(userFilter);
                  // totalItems = _catalystItemRepository.GetTotalOfItems(userFilter);
  
                  // Set up view model for passing to View
                  var viewModel = new CatalystModel
                  {
  
                      catalystItems = query.ToList(),
                      catalystFilter = userFilter,
  
                      /* Pass Paging properties to model*/
                      PagingInfo = new PagingInfo
                      {
                          CurrentPage = page,
                          ItemsPerPage = PageSize,
                          TotalItems = totalItems
  
                      },
                      ManufactureName = manufactureName
  
                  };
  
                  // View Data to be passed to SearchView
                  ViewData["catalystItems"] = viewModel;
  
  
                  return View(viewModel);
              }
  
              else
              {
                  var viewModel = new CatalystModel();
                  return View(viewModel);
              }
          }
  
          #endregion
  
          #region SEARCH VIEW
  
          /// &lt;summary&gt;
          /// Partial View used to display results from controller
          /// &lt;/summary&gt;
          /// &lt;param name="model"&gt; model passed via ViewData from List View&lt;/param&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          [ChildActionOnly]
          public ViewResult SearchView(CatalystModel model)
          {
              return View(model);
          }
  
          #endregion
  
      }
  }
  
  listView:
  
      &lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;CINet.Areas.CatalystSearch.Models.Entities.CatalystModel&gt;" %&gt;
  &lt;%@ Import Namespace="CINet.Areas.CatalystSearch.HtmlHelpers" %&gt;
  &lt;%@ Import Namespace="CINet.Areas.CatalystSearch.Models" %&gt;
  &lt;%@ Import Namespace="CINet.Areas.CatalystSearch.Models.Interfaces" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt;
  
      &lt;div&gt;
          &lt;center&gt;
              &lt;strong&gt;
                  &lt;%= Html.ValidationSummary("Please fill out required Fields") %&gt;&lt;/strong&gt; 
  
                  &lt;h1&gt;Catalyst Search Provider&lt;/h1&gt;
              &lt;hr /&gt;
              &lt;%-- "Search","Catalyst" --%&gt;
              &lt;% 
                  using (Html.BeginForm())
                  { %&gt;
              &lt;table border="1"&gt;
  
                 &lt;tr&gt;
                  &lt;td&gt;Enter Description (optional):&lt;/td&gt;
                  &lt;td&gt;
                  &lt;%: Html.TextBoxFor(x=&gt;x.Description) %&gt;
                  &lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                  &lt;td&gt;Enter Part Number (optional):&lt;/td&gt;
                  &lt;td&gt;
                  &lt;%: Html.TextBoxFor(x=&gt;x.ManufacturePartNumber) %&gt;
                  &lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;Choose Manufacture:
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;%: Html.DropDownListFor(x =&gt; x.ManufactureName, Model.GetAllManufactures()) %&gt;
                         &lt;%--  &lt;%: Html.DropDownList("ManufactureName", Model.GetAllManufactures(),"Choose Item")%&gt; --%&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &amp;nbsp
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="submit" name="Search" value="Search" /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;% } Html.EndForm();  %&gt;
              &lt;!-- RENDERS PARTIAL VIEW TO DISPLAY GRID WITH SEARCH RESULTS --&gt;
              &lt;% Html.RenderAction("SearchView", ViewData["catalystItems"]); %&gt;
              &lt;br /&gt;
          &lt;/center&gt;
      &lt;/div&gt;
      &lt;div class="pager"&gt;
  
         &lt;% if (Model.PagingInfo != null)
            { %&gt;
          &lt;%: Html.PageLinks(Model.PagingInfo, x =&gt; Url.Action("List", new { page = x, manufactureName = Model.catalystFilter.Manufacture, description = Model.catalystFilter.DescriptionFilter, manufacturePartNumber = Model.catalystFilter.ManufacturePartNumberFilter }))%&gt;
          &lt;% } %&gt;
      &lt;/div&gt;
  
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"&gt;
  &lt;/asp:Content&gt;
  
  
  SearchView:
  
      &lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;CINet.Areas.CatalystSearch.Models.Entities.CatalystModel&gt;" %&gt;
  &lt;%@ Import Namespace="CINet.Areas.CatalystSearch.HtmlHelpers" %&gt;
  &lt;%@ Import Namespace="CINet.Areas.CatalystSearch.Models" %&gt;
  
   &lt;div&gt;
      &lt;% if (Model.catalystItems != null)
         { %&gt;
          &lt;table class="CatalystTableSpacer"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      Contract Price
                  &lt;/td&gt;
                  &lt;td&gt;
                      Description
                  &lt;/td&gt;
                  &lt;td&gt;
                      Manufacture Name
                  &lt;/td&gt;
                  &lt;td&gt;
                      Manufacture Part Number
                  &lt;/td&gt;
                  &lt;td&gt;
                      MSRP Price
                  &lt;/td&gt;
                  &lt;td&gt;
                      Quantity Available
                  &lt;/td&gt;
  
              &lt;/tr&gt;
              &lt;% foreach (var items in Model.catalystItems)
                 {%&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;%: items.ContractPrice%&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;%: items.Description%&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;%: items.ManufactureName%&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;%: items.ManufacturePartNumber%&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                     &lt;%: items.MSRPrice%&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;%: items.QuantityAvailable%&gt;
                  &lt;/td&gt;
  
              &lt;/tr&gt;
              &lt;% }
         }
  
                  %&gt;
              &lt;/table&gt;
  
             &lt;/div&gt;
  </code></pre>
  
  <p>CatalystModel</p>
  
  <pre><code>   using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using CINet.Areas.CatalystSearch.Models.Entities;
  using System.ComponentModel.DataAnnotations;
  using CINet.Areas.CatalystSearch.Models.Repository;
  using CINet.Areas.CatalystSearch.Models.Interfaces;
  
  namespace CINet.Areas.CatalystSearch.Models.Entities
  {
      public class CatalystModel
      {
  
            #region PRIVATE FIELDS
  
          private string _connectionString = "Data Source=se-cinet-dev;Initial Catalog=cinet;User ID=sa;Password=Carouse1"; // connection string for SQL
          private ICatalystRepository _repository = null;
  
          #endregion
      #region PUBLIC PROPERTIES
  
      public IList&lt;CatalystItem&gt; catalystItems { get; set; }
      public PagingInfo PagingInfo { get; set; }
      public CatalystFilter catalystFilter { get; set; }
      public SelectList Manufactures { get; set; }
      public SelectList Categories { get; set; }
  
      [Required]
      public string ManufactureName { get; set; }
  
      public string Description { get; set; }
  
      public string ManufacturePartNumber { get; set; }
  
      #endregion
  
  
      #region CONSTRUCTOR
  
      /// &lt;summary&gt;
      /// Constructor instantiates SQL DB Connection
      /// &lt;/summary&gt;
      public CatalystModel()
      {
          _repository = new CatalystRepository(_connectionString);
       //   Manufactures = GetAllManufactures();
      }
  
  
  
      #endregion
  
      #region PUBLIC GET LISTS
  
      /// &lt;summary&gt;
      /// Returns ALL Manufactures in Database
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public SelectList GetAllManufactures()
      {
          SelectList manufactureNameSelectList;
          List&lt;Manufacture&gt; manufactureTempList = new List&lt;Manufacture&gt;();
  
          // Get List from DB
          manufactureTempList = _repository.GetManufactureList();
  
          // PUSH LIST INTO SELECT LIST
          manufactureNameSelectList = new SelectList(manufactureTempList, "ManufactureName", "ManufactureName");
  
          return manufactureNameSelectList;
      }
  
  
  
      #endregion
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The error happens in the ListView calling the SearchView:  </p>
  
  <p>&lt;% Html.RenderAction("SearchView", ViewData["catalystItems"]); %></p>
  
  <p>Any help??</p>
  
  <p>Actual Error:</p>
  
  <pre><code>Server Error in '/' Application.
  --------------------------------------------------------------------------------
  
  No parameterless constructor defined for this object. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
  
  Source Error: 
  
  
  Line 53:             &lt;!-- RENDERS PARTIAL VIEW TO DISPLAY GRID WITH SEARCH RESULTS --&gt;
  Line 54:           &lt;%-- &lt;% Html.RenderPartial("SearchView", ViewData["catalystItems"]); %&gt;
  Line 55:           --%&gt; &lt;% Html.RenderAction("SearchView", ViewData["catalystItems"]); %&gt;
  Line 56:             
  Line 57:             &lt;br /&gt;
  
  
  Source File: c:\Users\gcoleman\Documents\Source Code\Sandbox\Jonathan Henk\MVC\CINet\CINet\Areas\CatalystSearch\Views\CatalystSearch\List.aspx    Line: 55 
  
  Stack Trace: 
  
  
  [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) +98
     System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
     System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
     System.Activator.CreateInstance(Type type) +6
     System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +403
     System.Web.Mvc.DefaultModelBinder.BindSimpleModel(ControllerContext controllerContext, ModelBindingContext bindingContext, ValueProviderResult valueProviderResult) +544
     System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +479
     System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) +45
     System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +658
     System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +147
     System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +98
     System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +2504
     System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +548
     System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +475
     System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +181
     System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
     System.Web.Mvc.Controller.ExecuteCore() +136
     System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
     System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
     System.Web.Mvc.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__4() +65
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +44
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8`1.&lt;BeginSynchronous&gt;b__7(IAsyncResult _) +42
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
     System.Web.Mvc.&lt;&gt;c__DisplayClassa.&lt;EndProcessRequest&gt;b__9() +44
     System.Web.Mvc.&lt;&gt;c__DisplayClass4.&lt;Wrap&gt;b__3() +34
     System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +76
     System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +113
     System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result) +124
     System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1072
  
  [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
     System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3058371
     System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +77
     System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +28
     System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +22
     System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +766
     System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +98
     System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, Object routeValues) +65
     ASP.areas_catalystsearch_views_catalystsearch_list_aspx.__RenderContent1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\gcoleman\Documents\Source Code\Sandbox\Jonathan Henk\MVC\CINet\CINet\Areas\CatalystSearch\Views\CatalystSearch\List.aspx:55
     System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
     System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
     System.Web.UI.Control.Render(HtmlTextWriter writer) +10
     System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
     ASP.views_shared_site_master.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\gcoleman\Documents\Source Code\Sandbox\Jonathan Henk\MVC\CINet\CINet\Views\Shared\Site.Master:26
     System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
     System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +8820669
     System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31
     System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
     System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
     System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
     System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
     System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
     System.Web.UI.Control.Render(HtmlTextWriter writer) +10
     System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
     System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
     System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
     System.Web.UI.Page.Render(HtmlTextWriter writer) +29
     System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56
     System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060
  
  
  
  
  --------------------------------------------------------------------------------
  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237 
  </code></pre>