title: ASP.NET MVC Entity Framework CodeFirst Many To Many (CRUD) Follow Up
body: <p>This is a followup to this question: 
  <a href="https://stackoverflow.com/questions/9104880/asp-net-mvc-entity-framework-codefirst-many-to-many-crud">ASP.NET MVC Entity Framework CodeFirst Many To Many (CRUD)</a></p>
  
  <p>I have exactly the same problem. (BTW: I am learning MVC after a lot of experience with ASP.NET WebForms)</p>
  
  <p>(I need to ask a series of questions as I don't yet have 50 rep to add a comment.)</p>
  
  <p>The accepted answer to that question says to add one line of code "inside your query code" to which the questioner said it worked.</p>
  
  <p>My Create method is:</p>
  
  <pre><code>public ActionResult Create() {
      db.Students.Include(s =&gt; s.Courses);
      return View();
  }
  </code></pre>
  
  <p>My Create View is currently what has been generated by the scaffolding engine when I created the Controller:</p>
  
  <pre><code>@model CodeTest.Models.Course
  
  @{
      ViewBag.Title = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  @using (Html.BeginForm()) 
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Course&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true)
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Name, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Name)
                  @Html.ValidationMessageFor(model =&gt; model.Name)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Location, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Location)
                  @Html.ValidationMessageFor(model =&gt; model.Location)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Teacher, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Teacher)
                  @Html.ValidationMessageFor(model =&gt; model.Teacher)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>
  
  <p>My first thought is: what else did the questioner do so it "just worked"?</p>
  
  <p>This raises a series of questions:
  1. Where is "inside the query code". Is it inside the create method of the controller? I tried that (see above) and it didn't work.</p>
  
  <ol start="2">
  <li><p>Did a dropdown box appear on the scaffolding screen by adding this one line of code? Was rescaffolding required?  If so, how is that done?</p></li>
  <li><p>Was anything else required to be added to the create and edit views to allow the user to set a value for this many to many relationship?</p></li>
  </ol>