title: Unable to get value of DropDownListFor in controller on submit from view
body: <p>I am using a <code>@Html.DropDownListFor&lt;&gt;</code> in my page that is bound to my ViewModel but when I submit the page to the controller for processing I get the error "The Type filed is required." which is an error thrown since the proptery of my VM "Type" has the Data Annotation <code>[Required]</code>. I think is this due to the fact the <code>@Html.DropDownList&lt;&gt;</code> generates HTML code with <code>name=Type</code> while all the other HTML generated has <code>name=Section.XXXX</code> where XXX is the property name. I have been trying to figure out how to make the <code>@Html.DropDownList&lt;&gt;</code> generate the <code>name=Section.Type</code> property, assuming my theory is correct. So my question is really, is my theory correct and if so how to get it to generate the correct html and if not what might be wrong?</p>
  
  <p>Section EF Mode:</p>
  
  <pre><code>public class Section
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Int16 ID { get; set; }
  
      public Int64? LogoFileID { get; set; }
  
      [Required, MaxLength(250), Column(TypeName = "varchar")]
      public string RouteName { get; set; }
  
      [Required, MaxLength(15), Column(TypeName = "varchar")]
      public string Type { get; set; }
  
      [Required]
      public string Title { get; set; }
  
      public string Synopsis { get; set; }
  
      [ForeignKey("LogoFileID")]
      public virtual File Logo { get; set; }
  }
  </code></pre>
  
  <p>Section View Model:</p>
  
  <pre><code>public class SectionAddEditVM
  {
      public Section Section { get; set; }
      public List&lt;SelectListItem&gt; Type { get; set; }
      public string SelectedType { get; set; }
  
      public SectionAddEditVM()
      {
          Section = new Section();
          Type = new List&lt;SelectListItem&gt;();
          Type.Add(new SelectListItem { Value = "Books", Text = "Books" });
          Type.Add(new SelectListItem { Value = "Cinema", Text = "Cinema" });
          Type.Add(new SelectListItem { Value = "Collection", Text = "Collection" });
          Type.Add(new SelectListItem { Value = "Game", Text = "Game" });
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
      @Html.AntiForgeryToken();
      @Html.ValidationSummary(false)
  
      &lt;p&gt;
          &lt;label for="Title"&gt;Seciton Title:&lt;/label&gt; @Html.EditorFor(model =&gt; model.Section.Title)
          &lt;br /&gt;
          &lt;label for="RouteName"&gt;Section Route:&lt;/label&gt; @Html.EditorFor(model =&gt; model.Section.RouteName)
          &lt;br /&gt;
          &lt;label for="Type"&gt;Section Type:&lt;/label&gt; @Html.DropDownListFor(m =&gt; m.Type, new SelectList(Model.Type, "Text", "Value"))
          &lt;br /&gt;
          &lt;label for="LogoFile"&gt;Logo Image:&lt;/label&gt; &lt;input id="LogoFile" name="LogoFile" type="file" /&gt;
          &lt;br /&gt;
          &lt;label for="Synopsis"&gt;Synopsis:&lt;/label&gt; @Html.EditorFor(model =&gt; model.Section.Synopsis)
          &lt;br /&gt;
          &lt;input type="submit" value="Add new section" /&gt;
      &lt;/p&gt;
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    [Route("Add"), HttpPost, ValidateAntiForgeryToken]
      public ActionResult AddSection(SectionAddEditVM NewSection, HttpPostedFileBase LogoFile)
      {
          if (ModelState.IsValid)
          {
              try
              {
                  if (LogoFile != null &amp;&amp; LogoFile.ContentLength &gt; 0)
                  {
                      if (LogoFile.ContentType == "image/png")
                      {
                          string FileName = NewSection.Section.RouteName + "Logo";
                          NewSection.Section.LogoFileID = FileUploadHelper.UploadSiteImage("Logos", FileName, LogoFile);
                      }
                      else
                      {
                          ModelState.AddModelError("File Type", "Logo Files must be PNG files.");
                          return View(NewSection);
                      }
                  }
  
                  using (db)
                  {
                      db.Sections.Add(NewSection.Section);
                      db.SaveChanges();
                  }
  
                  //SiteUpdateHelper.RecordChange("New", "New Section", NewSection.Title, "Eagle_f90");
              }
              catch (Exception ex)
              {
                  ErrorSignal.FromCurrentContext().Raise(ex);
                  ModelState.AddModelError("Processing Error", "There was a problem processing the new section, please try again later.");
                  return View(NewSection);
              }
          }
          return View(NewSection);
      }
  </code></pre>
  
  <p>Generated HTML:</p>
  
  <pre><code>&lt;select id="Type" name="Type"&gt;&lt;option value="Books"&gt;Books&lt;/option&gt;
  &lt;option value="Cinema"&gt;Cinema&lt;/option&gt;
  &lt;option value="Collection"&gt;Collection&lt;/option&gt;
  &lt;option value="Game"&gt;Game&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>