title: MVC - Binding ICollection property
body: <p>I am using MVC and EF DB First. My models are created by EF. In my model i have two ICollection type properties. </p>
  
  <p>My problem is when i post my form, those properties are empty (I'm not sending them to view emty)</p>
  
  <p>My Model:</p>
  
  <pre><code>    public partial class Account
      {
          public Account()
          {
              this.Account_Level = new HashSet&lt;Account_Level&gt;();
              this.Account_Team = new HashSet&lt;Account_Team&gt;();
          }
  
          public long Id { get; set; }
          public string UserName { get; set; }
          public string Password { get; set; }
          public bool IsAdmin { get; set; }
  
          public virtual ICollection&lt;Account_Level&gt; Account_Level { get; set; }
          public virtual ICollection&lt;Account_Team&gt; Account_Team { get; set; }
      }
  </code></pre>
  
  <p>Note: My ICollection properties are not present in my view, but i need them back in my controller.</p>
  
  <p>Edit:</p>
  
  <p>I have added below code to my view. In my html, i can see my Icollection values are added as hidden but when i make the post the ICollection properties are still empty. So i am still not getting those values back.</p>
  
  <pre><code>for (int i = 0; i &lt; Model.Account_Level.Count(); i++)
  {
      @Html.HiddenFor(m =&gt; m.Account_Level.ElementAt(i).AccountId)
      @Html.HiddenFor(m =&gt; m.Account_Level.ElementAt(i).Id)
      @Html.HiddenFor(m =&gt; m.Account_Level.ElementAt(i).LevelId)
  }
  
  for (int i = 0; i &lt; Model.Account_Team.Count(); i++)
  {
      @Html.HiddenFor(m =&gt; m.Account_Team.ElementAt(i).AccountId)
      @Html.HiddenFor(m =&gt; m.Account_Team.ElementAt(i).Id)
      @Html.HiddenFor(m =&gt; m.Account_Team.ElementAt(i).TeamId)
  }
  </code></pre>