title: ASP.Net MVC returning value of a DropDown
body: <p>I am learning, and managed to make a nice info display page, displaying lists of transactions. However, I have no added  DropDown box, which has a list of Bank Accounts. It's defaulted to All.</p>
  
  <p>When the user selects an account, and presses the submit button, the page should then reloca with only transactions for that account.</p>
  
  <p>I have created the drop down, and the form for it, like this:</p>
  
  <pre><code>    &lt;form id="form1" runat="server"&gt;
  &lt;h2&gt;
      Transactions:&lt;/h2&gt;
  &lt;p&gt;
      &lt;%
          using (Html.BeginForm())
          {
      %&gt;
      Bank Account:
      &lt;% =Html.DropDownList("ddAccounts", Model.BankAccountItems)%&gt; &lt;input id="Submit1" type="submit" value="Select" /&gt;     
      &lt;%
          }
      %&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My model contains this:</p>
  
  <pre><code>    public class AccountTransactionDisplay
  {
      public AccountTransactionDisplay()
      {
          DisplayLines = new List&lt;AccountTransactionDisplayLine&gt;();
      }
  
      public SelectList BankAccountItems { get; set; }
      public List&lt;AccountTransactionDisplayLine&gt; DisplayLines {get; set; }
      public string ClosingBalance { get; set; }
  }
  
  public class BankAccountDropdownItem
  {
      public string Text {get; set;}   
      public string Value {get; set;}
  }
  
  public class AccountTransactionDisplayLine
  {
      public string RowColouring { get; set; }
      public string TransactionDate { get; set;}
      public string PayeeName { get; set; }
      public string Amount { get; set; }
      public bool AmountIsDebit { get; set; }
      public string CategoryName { get; set; }
      public string CostCenterName { get; set; }
      public string BudgetName { get; set; }
      public string RunningTotal { get; set; }
      public bool RunningTotalIsDebit { get; set; }
      public bool AlternateRowColour { get; set; }
      public bool HasSplitItems { get; set; }
  }
  </code></pre>
  
  <p>So, AccountTransactionDisplay is the model I pass to the view. In that model, I have this:</p>
  
  <pre><code> public SelectList BankAccountItems { get; set; }
  </code></pre>
  
  <p>That holds a list of items that are displayed in my Drop Down. That is being displayed correctly.</p>
  
  <p>However, when the user clicks the submit button, I am unsure how to get the selected value back.</p>
  
  <p>I thought that I would have a method in my controller that accepts the POST... So, I have added this:</p>
  
  <pre><code>        [HttpPost]
      public ActionResult Transactions(AccountTransactionDisplay model)
      {
          AccountTransactionDisplay trans = GetTransactions();
          return View(trans);
      }
  </code></pre>
  
  <p>And if I set a breakpoint, it is hitting this, but it seems model is empty. I need to add the id of the selected account ot the GetTransactions method, to do the filtering.</p>