The values ββfor the drop-down list should be in your existing view model:
public class WhateverViewModel { // All of your current viewmodel fields here public string SelectedCity { get; set; } public Dictionary<string, string> CityOptions { get; set; } }
Fill them in your controller with whatever values ββyou want (where SelectedCity is a numeric identifier), and then do the following in your view:
@Html.DropDownListFor(m => m.SelectedCity, new SelectList(Model.CityOptions, "Key", "Value", Model.SelectedCity))
If your values ββnever change, you can make them tough as a static member of your view model, and then do the following:
@Html.DropDownListFor(m => m.SelectedCity, new SelectList(WhateverViewModel.CityOptions, "Key", "Value", Model.SelectedCity))
In any case, this is the data for this view, so it belongs to your model. If you are not using view models, and this view is directly tied to a domain object; you must use them, and now is the right time to start.
Ant p source share