title: Dropdownlist ASP.NET MVC not updating Model
body: <p>I have two Model classes like so:</p>
  
  <p>Program:</p>
  
  <pre><code>public class Program
  {
      public int ProgramId { get; set; }
  
      public string Name { get; set; }
  
      public virtual Playlist chosenPlaylist { get; set; }
  
      public virtual IList&lt;Playlist&gt; Playlists { get; set; }
  }
  
  public class Playlist
  {
      public int PlaylistId { get; set; }
  
      public string Name { get; set; }
  
      public int NumberVotes { get; set; }
  
      public virtual IList&lt;Song&gt; Songs { get; set; }
  }
  </code></pre>
  
  <p>In my Edit Program View, I want to update the <code>chosenPlaylist</code> so I can allow the user to select none or one of the <code>Program</code>'s <code>Playlist</code>s. </p>
  
  <p>For example:</p>
  
  <p>Program 1:</p>
  
  <ul>
  <li>Playlist 1</li>
  <li>Playlist 2</li>
  </ul>
  
  <p>Chosen Playlist: Playlist 1</p>
  
  <p>So the user can then edit and select None (so no playlist), 1 (won't change anything) or 2 and that gets saved to the database.</p>
  
  <p>I've tried to create a dropdownlist in my Controller but it won't update. </p>
  
  <p>Here's what I have in both my GET and POST Edit <code>ActionResult</code>s:</p>
  
  <pre><code>ViewBag.chosenId = new SelectList(program.Playlists, "PlaylistId",
  "Name", program.chosenPlaylist.PlaylistId);
  </code></pre>
  
  <p>And in my View:</p>
  
  <pre><code>@Html.DropDownList("PlaylistId", (SelectList)ViewBag.chosenId)
  </code></pre>
  
  <p>This displays the list fine and pre-selects the chosen Playlist, if there is one (if not, I'll write code for it to default to the first). If there aren't playlists in a Program, that's easy to control. </p>
  
  <p>However, problems:</p>
  
  <ul>
  <li>Doesn't update my model. If Playlist 2 is the chosen one, for example, and I choose P1, it continues to display P2 after the POST event.</li>
  <li>I want to include an option in the dropdownlist for it not to pick any value (so, place a NULL in that field). Is that possible?</li>
  </ul>
  
  <p>There are no errors thrown, everything seems to work except for the most important part - updating the database.</p>