public static IEnumerable<SelectListItem> SelectLanguage(int? selectedLanguage) { List<SelectListItem> requestedList = new List<SelectListItem>(); var requestedLanguages = Server.DataBase.Languages.Get(); requestedList.Add(new SelectListItem() { Value = "", Text = GlobalRes.Language, Selected = true }); foreach (var language in requestedLanguages) { requestedList.Add(new SelectListItem() { Value = language.LCID.ToString(), Text = language.name, Selected = false }); } if (selectedLanguage.HasValue) { SelectListItem selectedLanguageItem = requestedList.Find(x => x.Value == selectedLanguage.Value.ToString()); if (selectedLanguageItem != null) selectedLanguageItem.Selected = true; } return requestedList; }
public static IEnumerable<SelectListItem> SelectCity(int lid, int? selectedCity) { List<SelectListItem> requestedList = new List<SelectListItem>(); var requestedCities = Server.DataBase.City.Get().Select(x => new CityView(x) { lid = lid }); requestedList.Add(new SelectListItem() { Value = "", Text = GlobalRes.City, Selected = true }); foreach (var city in requestedCities) { requestedList.Add(new SelectListItem() { Value = city.id.ToString(), Text = city.name, Selected = false }); } if (selectedCity.HasValue) { SelectListItem selectedCityItem = requestedList.Find(x => x.Value == selectedCity.Value.ToString()); if (selectedCityItem != null) selectedCityItem.Selected = true; } return requestedList; }