title: DropDownListFor post value NULL to database
body: <p>I have a Course Table and a Hole Table in SQL. There is a foreign Key in the hole Table that is set to the CourseId.</p>
  <p>This is so that when I create a hole I can assign it to the relevant course.</p>
  <p>In my View I have a dropdownlistfor that has a list of courses to select from when creating the hole. However when I try and post back the values the courseID does not post back.</p>
  <p>HoleViewModel</p>
  <pre><code> // GET: HoleViewModels/Create
      public ActionResult Create()
      {
          var dbcourse = db.Course.ToList();
  
          //Make selectlist, which is IEnumerable&lt;SelectListItem&gt;
          var courseNameDropdownList = new SelectList(db.Course.Select(item =&gt; new SelectListItem()
          {
              Text = item.CourseName.ToString(),
              Value = item.CourseId.ToString()
          }).ToList(), &quot;Value&quot;, &quot;Text&quot;);
  
          // Assign the Selectlist to the View Model   
          var viewCourse = new HoleViewModel()
          {
              Course = dbcourse.FirstOrDefault(),
              // The Dropdownlist values
              CourseNamesDropdownList = courseNameDropdownList,
  
          };
  
          
          return View(viewCourse);
      }
  
      // POST: HoleViewModels/Create
      // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
      // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = &quot;HoleId,HoleNumber,Par,Length,StrokeIndex,CourseId&quot;)]  HoleViewModel holeViewModel)
      {
          if (ModelState.IsValid)
          {
              db.HoleViewModels.Add(holeViewModel);
              db.SaveChanges();
              return RedirectToAction(&quot;Index&quot;);
          }
  
          
          return View(holeViewModel);
      }
  </code></pre>
  <p>The Create.cshtml</p>
  <pre><code>@using (Html.BeginForm()) 
  </code></pre>
  <p>{
  @Html.AntiForgeryToken()</p>
  <pre><code>&lt;div class=&quot;form-horizontal&quot;&gt;
      &lt;h4&gt;HoleViewModel&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
      &lt;div class=&quot;form-group&quot;&gt;
          @Html.LabelFor(model =&gt; model.HoleNumber, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
          &lt;div class=&quot;col-md-10&quot;&gt;
              @Html.EditorFor(model =&gt; model.HoleNumber, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
              @Html.ValidationMessageFor(model =&gt; model.HoleNumber, &quot;&quot;, new { @class = &quot;text-danger&quot; })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;form-group&quot;&gt;
          @Html.LabelFor(model =&gt; model.Par, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
          &lt;div class=&quot;col-md-10&quot;&gt;
              @Html.EditorFor(model =&gt; model.Par, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
              @Html.ValidationMessageFor(model =&gt; model.Par, &quot;&quot;, new { @class = &quot;text-danger&quot; })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;form-group&quot;&gt;
          @Html.LabelFor(model =&gt; model.Length, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
          &lt;div class=&quot;col-md-10&quot;&gt;
              @Html.EditorFor(model =&gt; model.Length, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
              @Html.ValidationMessageFor(model =&gt; model.Length, &quot;&quot;, new { @class = &quot;text-danger&quot; })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;form-group&quot;&gt;
          @Html.LabelFor(model =&gt; model.StrokeIndex, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
          &lt;div class=&quot;col-md-10&quot;&gt;
              @Html.EditorFor(model =&gt; model.StrokeIndex, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
              @Html.ValidationMessageFor(model =&gt; model.StrokeIndex, &quot;&quot;, new { @class = &quot;text-danger&quot; })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;form-group&quot;&gt;
          @Html.LabelFor(model =&gt; model.Course.CourseId, &quot;CourseId&quot;, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
          &lt;div class=&quot;col-md-10&quot;&gt;
              @Html.DropDownListFor(model =&gt; model.Course.CourseId, Model.CourseNamesDropdownList, &quot;Please select from List&quot;, new { @class = &quot;form-control&quot; })
              @Html.ValidationMessageFor(model =&gt; model.CourseId, &quot;&quot;, new { @class = &quot;text-danger&quot; })
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  <p>So when the holeview posts back holeNumber, Par, Length, StrokeIndex, CourseID. it passes all data into the hole table other than the courseId which it posts a null.</p>
  <p>What am I missing from the POST to get the CourseId to be entered in the Database.</p>