title: Get posted selected item from DropDownList in ASP MVC
body: <p><strong>Controller</strong></p>
  
  <pre><code>public ActionResult Create()
  {
     return View(new PageViewModel());
  } 
  
  [HttpPost]
  public ActionResult Create(Page page)
  {
     try
     {
        repPage.Add(page);
        repPage.Save();
  
        return RedirectToAction("Edit");
     }
     catch
     {
        return View(new PageViewModel());
     }
  }
  </code></pre>
  
  <p><strong>PageViewModel</strong></p>
  
  <pre><code>public class PageViewModel
  {
      public Page Page { get; set; }
      public List&lt;Template&gt; Templates { get; set; }
  
      private TemplateRepository repTemplates = new TemplateRepository();
  
      public PageViewModel()
      {
          Page = new Page();
          Templates = repTemplates.GetAllTemplates().ToList(); 
      }
  }
  </code></pre>
  
  <p><strong>Parts of my View</strong></p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;Website.Models.PageViewModel&gt;" %&gt;
  
  &lt;%= Html.TextBoxFor(model =&gt; model.Page.Name, new { @style = "width:300px;" })%&gt;
  
  &lt;%= Html.DropDownListFor(model =&gt; model.Page.Template, new SelectList(Model.Templates, "ID", "Name"), new { @style = "width:306px;" })%&gt;
  </code></pre>
  
  <p><strong>Template:</strong>
  ID
  Name<br>
  <strong>Page:</strong>
  ID
  Name
  TemplateID</p>
  
  <p>My dropdownlist is populated correctly in the view, no problems there. My problem is that I dont get the selected value from the dropdownlist.</p>
  
  <p>In my controller I i put a breakpoint in <code>Edit</code> and see that the <code>Name</code> textbox is populated with the value I type into it. But the selected from the dropdownlist is set to null.</p>
  
  <p><a href="http://www.mgmweb.no/images/debug.jpg" rel="nofollow noreferrer">alt text http://www.mgmweb.no/images/debug.jpg</a></p>
  
  <p>Am I missing something, I thought it should set the correct <code>Template</code> value into the <code>Page</code> object. What am I doing wrong?</p>