title: MVC4 Automatically mapped my view model?
body: <p>I began to create my controller for the parent model listed below. I am using view models for all my views, but before I got around to adding the logic for the Create (Post) action I just hit submit for the hell of it thinking my viewmodel would not map to my model.</p>
  
  <p>To my surprise it actually worked. I am using AutoMapper and have set up all the mappings for the child models to their corresponding models, but not the parent model (as absent in the post result). What is going on here that MVC has allowed such magic to happen? </p>
  
  <p>Model:</p>
  
  <pre><code>public partial class ParentModel
      {
          public int Id { get; set; }
          public int Child1Id { get; set; }
          public int Child2Id { get; set; }
          public int Child3Id { get; set; }
          public int Child4Id { get; set; }
          //other data
          public virtual Child1 Child1 { get; set; }
          public virtual Child2 Child2 { get; set; }
          public virtual Child3 Child3 { get; set; }
          public virtual Child4 Child4 { get; set; }
      }
  </code></pre>
  
  <p>View Model:</p>
  
  <pre><code>public class ParentCreateViewModel
      {
          //other data
          public Child1ViewModel Child1 { get; set; }
          public Child2ViewModel Child2 { get; set; }
          public Child3ViewModel Child3 { get; set; }
          public Child4ViewModel Child4 { get; set; }
      }
  </code></pre>
  
  <p>View (Create.cshtml):</p>
  
  <pre><code>@model Project.ViewModels.ParentCreateViewModel
  @*EditorTemplates and such*@
  </code></pre>
  
  <p>Controller (Get):</p>
  
  <pre><code>public ActionResult Create()
      {
          //some list logic
          return View();
      }
  </code></pre>
  
  <p>Controller (Post - I haven't yet changed it to the ParentCreateViewModel or AutoMapped it back to ParentModel):</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Create(ParentModel parentModel)
  {
      if (ModelState.IsValid)
      {
          db.ParentModels.Add(parentModel);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  
      //some list logic
      return View(parentModel);
  }
  </code></pre>
  
  <p>My parent model and all child models are persisted correctly to the database. Does MVC do some kind of behind the scene binding? Shouldn't it be expecting a ParentCreateViewModel?</p>