title: Making model binding work for a model with no default constructor
body: <p>I’ve been trying to figure a way to have a model-binding go on with a model with a constructor with arguments.</p>
  
  <p>the action: </p>
  
  <pre><code> [HttpPost]
          public ActionResult Create(Company company, HttpPostedFileBase logo)
          {
              company.LogoFileName = SaveCompanyLogoImage(logo);
              var newCompany = _companyProvider.Create(company);
              return View("Index",newCompany);
          }
  </code></pre>
  
  <p>and the model</p>
  
  <pre><code>public  Company(CustomProfile customProfile)
          {
              DateCreated = DateTime.Now;
              CustomProfile = customProfile;
          }
  </code></pre>
  
  <p>I've done my research and seems I need to mess around with my ninjectControllerfactory:</p>
  
  <pre><code>  public class NinjectControllerFactory : DefaultControllerFactory
      {
          private readonly IKernel ninjectKernel;
  
          public NinjectControllerFactory()
          {
              ninjectKernel = new StandardKernel();
              AddBindings();
          }
  
          protected override IController GetControllerInstance(RequestContext requestContext,
                                                               Type controllerType)
          {
              return controllerType == null
                         ? null
                         : (IController) ninjectKernel.Get(controllerType);
          }
  
          private void AddBindings()
          {
              ninjectKernel.Bind&lt;IAuthProvider&gt;().To&lt;FormsAuthProvider&gt;();
              ninjectKernel.Bind&lt;IMembershipProvider&gt;().To&lt;MembershipProvider&gt;();
              ninjectKernel.Bind&lt;ICustomProfileProvider&gt;().To&lt;CustomProfileProvider&gt;();
              ninjectKernel.Bind&lt;ICompanyProvider&gt;().To&lt;CompanyProvider&gt;();
          }
      }
  </code></pre>
  
  <p>I also feel I need to modify my model binder but I'm not clear on the way forward:</p>
  
  <pre><code> public class CustomProfileModelBinder : IModelBinder
  {
      private const string sessionKey = "CustomProfile";
  
      #region IModelBinder Members
  
      public object BindModel(ControllerContext controllerContext,
                              ModelBindingContext bindingContext)
      {
          // get the Cart from the session 
          var customProfile = (CustomProfile) controllerContext.HttpContext.Session[sessionKey];
          // create the Cart if there wasn't one in the session data
          if (customProfile == null)
          {
              customProfile = new CustomProfile("default name");
              controllerContext.HttpContext.Session[sessionKey] = customProfile;
          }
          // return the cart
          return customProfile;
      }
  
      #endregion
  }
  </code></pre>
  
  <p>Hope this explains my issue, I'm sorry if its a rather long winded question!</p>
  
  <p>Thanks for any assistance </p>