title: Setting selected value of a Select using JQuery from an MVC model property
body: <p>I am am filling a dropdown using Ajax</p>
  
  <pre><code>$(document).ready(function() {
  
      var ID = $("#ID").val();
  
      fillDropdown(ID); //fills the dropdown via an $.ajax call
  
      var anotherID = @Model.AnotherID;
  
      //alert(anotherID);
      $("#AnotherID").val(anotherID); //try to set the selected value
  
  });
  </code></pre>
  
  <p>The dropdown is defined in the page as:</p>
  
  <pre><code>@Html.DropDownListFor(x =&gt; x.AnotherID, Enumerable.Empty&lt;SelectListItem&gt;())
  </code></pre>
  
  <p>The line to set the selected value of the dropdown is:
  $("#AnotherID").val(anotherID);</p>
  
  <p>and it only works if I uncomment the alert just above!</p>
  
  <p>Any ideas why?</p>