I have the following statement:
<%: Html.DropDownList("dropCity", new[] { new SelectlistItem { Text = "City1", Value = 1}, new SelectlistItem { Text = "City2", Value = 2}, new SelectlistItem { Text = "City3", Value = 3}})%>
Suppous that my controller sent to the aspx page that contais this dropdownlist a variable with the value “3”, how can I set this dropdownlist to select this option when the page loads ?
Thanks for the help !
Use view models:
then have your controller populate this view model:
and finally in your strongly typed view: