title: ASP.Net MVC - How to include / exclude binding of certain child collection / enumerable properties?
body: <p>Details:</p>
  
  <ul>
  <li>ASP.Net MVC 5</li>
  <li>.Net 4.5</li>
  <li>MVVM</li>
  <li>Entity Framework 6 Code First</li>
  </ul>
  
  <p>I have ViewModels with complex properties on them.  I have read about how I can use the <a href="https://msdn.microsoft.com/en-us/library/system.web.mvc.bindattribute%28v=vs.118%29.aspx" rel="nofollow">BindAttribute</a> to include or exclude properties for model bidning and got basic properties working with this.</p>
  
  <p>However one thing I cannot find is how to control the binding of child properties within a collection property.  For example I have the following </p>
  
  <pre><code>[Bind(Include = "Model.Id, Model.Positions.StartDate")]
  public class ProjectViewModel
  {
      public Project Model {get;set;}
  
      public ProjectViewModel(Project project)
          : base(project)
      {
            Model = project;
      }
  
      public ProjectViewModel()
      {
  
      }
  
  }
  </code></pre>
  
  <p>A Project has a list of Positions:</p>
  
  <pre><code>public class Project : BaseEntity
  {
      .
      .
      .
  
      public virtual IList&lt;Position&gt; Positions
      {
          get;
          set;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>And a Position has a start and end date:</p>
  
  <pre><code>public class Position : BaseEntity
  {
      [SensibleDateTime]
      public DateTime StartDate { get; set; }
  
      [SensibleDateTime]
      public DateTime EndDate { get; set; }
  
      [Required]
      [ForeignKey("Project")]
      public Int64 ProjectID { get; set; }
      public virtual Project Project { get; set; }
  }
  </code></pre>
  
  <p>I have a screen using the Project View Model with a grid of positions where the user is allowed to change the start and end date of those positions. I do not want to allow them to let them amend any other properties of the Position including by manipulating the request / post to the server.</p>
  
  <p>I am writing my own custom model binder which inherits from the DefaultModelBinder which gets the original entity out the database. I just want to bind permitted bound fields on top to get these new values and all the original values will already exist.</p>
  
  <p>I am aware I could get the original entity out the database inside the controller instead and map the bound start and end date onto the entity manually.  I want to avoid this if possible and make the controller code as simple as possible as this will be a very common task.  Additionally it seems like using standard MVC mechanisms would be the preferred approach.</p>
  
  <p>I have tried the following bind statement on the Project View Model:</p>
  
  <pre><code>[Bind(Include = "Model.Positions.StartDate")]
  </code></pre>
  
  <p>None of the new values are bound including the start date of the positions.  If I write a simple include for a property directly on the Project View Model or Model it works.</p>
  
  <p>How do you write a Bind attribute statement that refers to a property within an entity collection?</p>