title: Overloaded ViewModel Constructor and HttpPost in ASP.NET MVC
body: <p>The closest question I found in StackOverflow to what I have is
  <a href="https://stackoverflow.com/questions/9413313/posting-data-when-my-view-model-has-a-constructor-does-not-work">Posting data when my view model has a constructor does not work</a></p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>    public class Customer
      {
          public int Id { get; set; }                
          public string FirstName { get; set; }
          public string LastName { get; set; }
      }
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>    public class CustomerViewModel
      {
          public Customer Customer { get; set; }
  
          public CustomerViewModel(Customer customer)
          {
              Customer = customer;        
          }
      }
  </code></pre>
  
  <p><strong>Controller Code</strong></p>
  
  <pre><code>    public ActionResult CreateCustomer()
      {
          Customer c = new Customer();
          CustomerViewModel cvm = new CustomerViewModel(c);
          return View(cvm);
      }
  
      [HttpPost]
      public ActionResult CreateCustomer(CustomerViewModel customer)
      {
         // do something here
      }
  </code></pre>
  
  <p><strong>View Code</strong></p>
  
  <pre><code>    @model Blah.Models.CustomerViewModel
  
      @{
          ViewBag.Title = "CreateCustomer";
       }
  
      &lt;h2&gt;CreateCustomer&lt;/h2&gt;
  
      @using (Html.BeginForm()) 
      { 
          &lt;div class="editor-label"&gt;
            @Html.LabelFor(model =&gt; model.Customer.FirstName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
            @Html.EditorFor(model =&gt; model.Customer.FirstName)
            @Html.ValidationMessageFor(model =&gt; model.Customer.FirstName)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
            @Html.LabelFor(model =&gt; model.Customer.LastName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
            @Html.EditorFor(model =&gt; model.Customer.LastName)
            @Html.ValidationMessageFor(model =&gt; model.Customer.LastName)
          &lt;/div&gt;
  
          &lt;p&gt;
            &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <p><img src="https://i.stack.imgur.com/e14Cg.png" alt="enter image description here"></p>
  
  <p><strong>Solutions that just get rid of the error but not helpful</strong></p>
  
  <ul>
  <li>Adding a Default Constructor (parameter is empty - doesn't serve my purpose)</li>
  <li>Dont have the overloaded constructor (My Model will be empty then)</li>
  </ul>
  
  <p><strong>Question</strong></p>
  
  <p>I guess I need a custom model binder here. Don't know how to create one :-(</p>
  
  <p>(or)</p>
  
  <p>I would like to know what other options I have here</p>