title: ASP.NET MVC @Html.EditorFor(model => model.property) But
body: <p>What about if I have a navigation property? I have a collection of another model in the model I'm trying to edit. I want to display a list of checkboxes for each object in the collection property. So far, this is what I tried...</p>
  
  <pre><code>@{
  
              foreach (var category in ViewBag.Categories)
              {
                  if (Model.Categories.Contains(category))
                  {
                      &lt;input type="checkbox" name="selected-categories" value="category.CategoryId" checked="checked" /&gt;@category.Name
                  }
                  else
                  {
                      &lt;input type="checkbox" name="selected-categories" value="@category.CategoryId" /&gt;@category.Name
                  }
              }   
           }
  </code></pre>
  
  <p>But it fails with an EntityCommandExecutionException. In my if statement, how can I access the model.Categories like I do in something like <code>@Html.EditorFor(model =&gt; model.Id)</code>???</p>