title: No parameterless constructor defined for this object. in ASP.NET MVC Controller
body: <p>I am sure this is quite straightforward but I am a bit stuck here. The routing defined for my app is just the default. I have the following controller defined.</p>
  
  <pre><code>namespace Baynes.Wedding.Web.Controllers
  {
      public class AdminController : Controller
      {
          private readonly IAuthProvider _authProvider;
          private readonly IDocumentRepository _documentRepository;
  
          public AdminController(IAuthProvider authProvider, IDocumentRepository documentRepository)
          {
              _authProvider = authProvider;
              _documentRepository = documentRepository;
          }
  
          public ViewResult EditDocument(int id)
          {
              var document = _documentRepository.Select(id);
  
              return View(new DocumentEditViewModel(document));
          }
  
          [HttpPost]
          public ActionResult EditDocument(DocumentEditViewModel model)
          {
              if (ModelState.IsValid)
              {
                  _documentRepository.Update(model.ToDocument());
                  return RedirectToAction("ListDocuments");
              }
  
              return View();
          }
      }
  }
  </code></pre>
  
  <p>When I navigate to <code>/Admin/EditDocument/1/</code> then the first action executes exactly as expected, rendering the following view:-</p>
  
  <pre><code>&lt;h2&gt;@ViewBag.Title&lt;/h2&gt;
  @using (Html.BeginForm("EditDocument", "Admin", FormMethod.Post)) {
      @Html.ValidationSummary(true)
      @Html.HiddenFor(m =&gt; Model.Id)
      &lt;div&gt;
          @Html.LabelFor(m =&gt; Model.Title)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.TextBoxFor(m =&gt; Model.Title)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.LabelFor(m =&gt; Model.Body)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.TextAreaFor(m =&gt; Model.Body)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.LabelFor(m =&gt; Model.Url)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.TextBoxFor(m =&gt; Model.Url)
      &lt;/div&gt;
  
      &lt;input type="submit" value="Edit" /&gt;
  }
  </code></pre>
  
  <p>On submitting this I get an error:-</p>
  
  <p><code>No parameterless constructor defined for this object.</code> Other questions seemingly related questions <a href="https://stackoverflow.com/questions/12605445/mvc-no-parameterless-constructor-defined-for-this-object">MVC: No parameterless constructor defined for this object</a> suggest that it is a to do with the IoC container not being set up properly, but surely the fact that the first action executes without a problem means that isn't the problem here?</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Regards.</p>
  
  <p>Simon</p>