title: Select from Dropdown in View and pass back to Controller
body: <p>I have a model like this:</p>
  
  <pre><code>public class UserProfile
  {
      public Guid ID { get; set; }
      public string DisplayName { get; set; }
      public Language PreferredLang { get; set; }
  }
  public class Language
  {
      [Key]
      public int LanguageID { get; set; }
      public string LanguageCode { get; set; }
      public string DisplayName { get; set; }
  }
  </code></pre>
  
  <p>And I want to be able to select preferred language from dropdown. </p>
  
  <p>In controller I get list of languages and put it in ViewBag. In view I load this list. Then i want to save selection.</p>
  
  <p>My controller: </p>
  
  <pre><code>public ActionResult EditProfile()
  {
      List&lt;Language&gt; langauges =  Logic.GetAllLanguages();
      ViewBag.Languages = langauges;
      UserProfile profile = GetUserProfile();
      return View(profile);
  }
  </code></pre>
  
  <p>An my view:</p>
  
  <pre><code>@using (Html.BeginForm()) {
  
      @Html.EditorFor(model =&gt; model.DisplayName)
      &lt;div class="display-field"&gt;
          @Html.DropDownListFor(x =&gt; x.PreferredLang, new SelectList(ViewBag.Languages, "LanguageID", "DisplayName") as SelectList)
  
      &lt;/div&gt;
      &lt;input type="submit" value="Save" /&gt;
  }
  </code></pre>
  
  <p>When user clicks "Save", <code>element</code> object passed to controller has <code>DisplayName</code>, but <code>PreferredLang</code> is always null. <strong>How can I pass Language back to controller?</strong></p>
  
  <pre><code>[HttpPost]
  public ActionResult EditProfile(UserProfile element)
  {
      //save element
  }
  </code></pre>