title: MVC Core DropDownList selected value ignored
body: <p>I am trying to access my page at: <a href="https://localhost:44319/Analyze/Index/6" rel="nofollow noreferrer">https://localhost:44319/Analyze/Index/6</a></p>
  
  <p>The problem is that my drop down list always selects the first item in the list instead of the one provided by ID. While stepping through the debugger, before the View() is returned, I see that the SelectList was populated correctly. </p>
  
  <p><strong>AnalyzeController.cs</strong></p>
  
  <pre><code>public IActionResult Index(int? Id)
  {
      return Index(Id ?? getStatementEndingById(Id).StatementEndingId);
  }
  
  [HttpPost]
  public IActionResult Index(int StatementEndingId)
  {
      var statementEnding = getStatementEndingById(StatementEndingId);
  
      ViewBag.StatementEndingId = new SelectList(
                    _context.StatementEnding.OrderByDescending(s =&gt; s.StatementEndingId), 
                    "StatementEndingId", 
                    "Name", 
                    statementEnding);
  
      return View(getPayments(statementEnding));
  }
  
  private StatementEnding getStatementEndingById(int? statementEndingId)
  {
      StatementEnding statementEnding;
      if (statementEndingId.HasValue)
      {
          statementEnding = _context.StatementEnding.FirstOrDefault(s =&gt; s.StatementEndingId == statementEndingId);
      }
      else
      {
          statementEnding = _context.StatementEnding.OrderByDescending(s =&gt; s.StatementEndingId).FirstOrDefault();
      }
  
      return statementEnding;
  }
  </code></pre>
  
  <p><strong>Setting DropDownList in Razor</strong></p>
  
  <pre><code>@Html.DropDownList("StatementEndingId", null, new { @class = "form-control mb-2 mr-sm-2" })
  </code></pre>
  
  <p>I am using ASP.NET Core 2.1.</p>
  
  <p>Any suggestions are much appreciated. Thanks in advance.</p>