title: .NET MVC 4 Strongly typed ViewModel containing Strongly typed Model with EditorFor and EditorTemplate partial view not binding
body: <p>There has been a lot of questions about this... but somehow I can't get this binding to work and I'm still getting null values in my posted View Model. This is MVC 4. </p>
  
  <p>Here is the Main View Model</p>
  
  <pre><code>public class RoleVM {
  
  [Required]
  [Display(Name = "Name of the Role")]
  public string Role {get; set;}
  
  public IEnumerable&lt;RolePermission&gt; permissions { get; set; }
  
  }
  </code></pre>
  
  <p>Here is the RolePermission Class</p>
  
  <pre><code>public class RolePermission {
  
  public int id;
  
  public bool permission_value;
  
  public string name { get; set; } 
  
  }
  </code></pre>
  
  <p>Here is GET Create Method in the controller </p>
  
  <pre><code>public ActionResult Create() {
  
          RoleVM role_vm = new RoleVM();
  
          var allpermissions = from p 
          in permission_repo.GetPermissions()
          select p; 
  
          role_vm.permissions = from p 
          in allpermissions 
          select new RolePermission
          { name = p.name, id = p.PermissionId, permission_value = false };
  
          return View(role_vm);
      }
  </code></pre>
  
  <p>Here is the Create.cshtml file </p>
  
  <pre><code>@model RoleVM
  @using (Html.BeginForm("Create", "Role", 
  FormMethod.Post, new { @class = "permission_form" }))
  {
  @Html.ValidationSummary(true)
  
  &lt;fieldset&gt;
      &lt;legend&gt;RoleVM&lt;/legend&gt;
  
      &lt;div class="form-item"&gt;
          @Html.LabelFor(model =&gt; model.Role)
  
          @Html.EditorFor(model =&gt; model.Role)
          @Html.ValidationMessageFor(model =&gt; model.Role)
      &lt;/div&gt;
  
     @Html.EditorFor(model =&gt; model.permissions)
  
      &lt;p&gt;
          &lt;input class="submit-btn" type="submit" value="Create" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>Next here is the rolepermissions.cshtml file located in ~/Views/Shared/EditorTemplates</p>
  
  <pre><code>@model RolePermission
  
  &lt;div class="form-item"&gt;
        @Html.HiddenFor(modelItem =&gt; modelItem.id) 
        @Html.LabelFor(modelItem =&gt; modelItem.permission_value, Model.name)
        @Html.CheckBoxFor(modelItem =&gt; modelItem.permission_value) 
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is an example of one of the html items that is rendered on page  </p>
  
  <pre><code>&lt;div class="form-item"&gt;
  
        &lt;input data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." id="permissions_2__id" name="permissions[2].id" type="hidden" value="3" /&gt; 
  
        &lt;label for="permissions_2__permission_value"&gt;Role-Edit&lt;/label&gt;
        &lt;input data-val="true" data-val-required="The Boolean field is required."  id="permissions_2__permission_value" name="permissions[2].permission_value"
   type="checkbox" value="true" /&gt;&lt;input name="permissions[2].permission_value"  type="hidden" value="false" /&gt; 
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Finally here is the Create POST method </p>
  
  <pre><code>    [HttpPost]
      public ActionResult Create(RoleVM rolevm)
      {
  
          //In here rolevm.role is populated based on the textbox input
          //However rolevm.permissions is there with the correct 
          //number of items, but the values all are not binded
          // id is null, name is empty, and permission_value is false 
          // regardless of which checkboxes were checked 
  
  
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>Any help on the binding issue with the posted model would be really great. </p>