I am am filling a dropdown using Ajax
$(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
});
The dropdown is defined in the page as:
@Html.DropDownListFor(x => x.AnotherID, Enumerable.Empty<SelectListItem>())
The line to set the selected value of the dropdown is: $("#AnotherID").val(anotherID);
and it only works if I uncomment the alert just above!
Any ideas why?