title: Asp.Net MVC with Drop Down List, and SelectListItem Assistance
body: <p>I am trying to build a Dropdownlist, but battling with the Html.DropDownList rendering.</p>
  
  <p>I have a class:</p>
  
  <pre><code>public class AccountTransactionView
  {
      public IEnumerable&lt;SelectListItem&gt; Accounts { get; set; }
      public int SelectedAccountId { get; set; }
  }
  </code></pre>
  
  <p>That is basically my view model for now. The list of Accounts, and a property for returning the selected item.</p>
  
  <p>In my controller, I get the data ready like this:</p>
  
  <pre><code>public ActionResult AccountTransaction(AccountTransactionView model)
  {
      List&lt;AccountDto&gt; accounts = Services.AccountServices.GetAccounts(false);
  
      AccountTransactionView v = new AccountTransactionView
      {
          Accounts = (from a in accounts
                      select new SelectListItem
                      {
                          Text = a.Description,
                          Value = a.AccountId.ToString(),
                          Selected = false
                      }),
      };
  
      return View(model);
  }
  </code></pre>
  
  <p>Now the problem:</p>
  
  <p>I am then trying to build the Drop down in my view:</p>
  
  <pre><code>&lt;%=Html.DropDownList("SelectedAccountId", Model.Accounts) %&gt;
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <p>The ViewData item that has the key 'SelectedAccountId' is of type 'System.Int32' but must be of type 'IEnumerable'.</p>
  
  <p>Why would it want me to return the whole list of items? I just want the selected value. How should I be doing this?</p>