title: ASP.NET MVC: passing a complex viewmodel to controller
body: <p>firs of all i searched for my question but couldnt find anything that helped me get any further.</p>
  
  <p>i am trying to implement a view which allows me to set permissions for the current user.</p>
  
  <p>As the data-structure i use following recursive class where each PermissionTree-Object references the sub-permissions (permissions are hierarchically structured in my application) :</p>
  
  <pre><code>public class PermissionTree
  {
          public Permission Node; //the permission object contains a field of type SqlHierarchyId if that is relevant
          public bool HasPermission;
          public IList&lt;PermissionTree&gt; Children;
     //i cut out the constructors to keep it short ...
  }
  </code></pre>
  
  <p>here is how the controller looks like:</p>
  
  <pre><code>//this is called to open the view
   public ActionResult Permissions()
      {
          //pass the root element which contains all permission elements as children (recursion)
          PermissionTree permissionTree = PopulateTree();//the fully populated permission-tree
          return View(permissionTree);
      }
  
  //this is called when i submit the form
      [HttpPost]
      public ActionResult Permissions(PermissionTree model)
      {
          SetPermissions(model);
          ViewData["PermissionsSaved"] = true;
  
          return View(model);//return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>in am using a strongly typed view like this:</p>
  
  <pre><code>@model PermissionTree
  //....
   @using (Html.BeginForm("Permissions", "Permission", null, FormMethod.Post, new { @class = "stdform stdform2" }))
  {    
  &lt;input name="save" title="save2" class="k-button" type="submit" /&gt;
  
  &lt;div class="treeview"&gt;
  //i am using the telerik kendoUI treeview
      @(Html.Kendo().TreeView()
              .Name("Permissions")
              .Animation(true)
              .ExpandAll(true)
              .Checkboxes(checkboxes =&gt; checkboxes
                  .CheckChildren(true)
              )
              .BindTo(Model, mapping =&gt; mapping
                  .For&lt;PermissionTree&gt;(binding =&gt; binding
                  .Children(c =&gt; c.Children)
                  .ItemDataBound( (item, c) =&gt; {
                      item.Text = c.Node.PermissionName;
                      item.Checked = c.HasPermission;
                  })
  
                  )
              )
        )
  </code></pre>
  
  <p>ok, so when i click the button, i want my viewmodel to be sent to the controller action that is decorated with <code>[HttpPost]</code>. But when i debug the application, the received model does not really contain my data (it is not null though).
  Does anyone know how i can achieve my goal and get the whole viewmodel?</p>
  
  <p>best regards,
  r3try</p>