public void FillCityDropdown(int?cityId) { DataTable dtLocation = new DataTable(); UserDetails objUserDetails = new UserDetails(); dtLocation = objUserDetails.GetCity(); IList <CityModel> items = dtLocation.AsEnumerable().Select(row => new CityModel { CityId = row.Field <int>("CityId"), CityName = row.Field <string>("CityName") }).ToList(); var list = new SelectList(items, "CityId", "CityName", cityId); ViewData["CityName"] = list; }
private void FillCityDrodown() { DataTable dtContact = new DataTable(); UserDetails objUserDetails = new UserDetails(); dtContact = objUserDetails.GetCity(); IList <CityModel> items = dtContact.AsEnumerable().Select(row => new CityModel { CityId = row.Field <int>("CityId"), CityName = row.Field <string>("CityName") }).ToList(); var list = new SelectList(items, "CityId", "CityName"); ViewBag.CityId = list; }