public ActionResult UserProfile(int?id) { UserEntities db = new UserEntities(); ProfileViewModel model = new ProfileViewModel(); HomeService homeService = new HomeService(); //HomeViewModel var city = db.tbl_city.ToList(); var a = homeService.optionListState(); model.Cities = db.tbl_city.Select(x => new citymodel { cityid = x.Cityid, cityname = x.Cityname }).ToList(); model.Countries = homeService.CountryStateList("Country"); model.SelectedCountry = 233; var states = homeService.CountryStateList("states"); model.States = states.Where(x => x.country_id == 233).ToList(); //model.States = CountryStateList("states").Select(x => new SelectListItem //{ // Text = x.name, // Value = x.id.ToString() //}).ToList(); //model.SelectedState = model.States.Where(x => x.country_id == 233).Select(x => x.id).FirstOrDefault(); // //.Select(x => new int { // // });//; 1456; if (id > 0) { var userlist = homeService.AddOrEdit(id); var seletedcityIds = db.tbl_user.Where(x => x.Userid == id).Select(x => x.CityIds).FirstOrDefault(); userlist.Cityids = seletedcityIds.Split(',').ToArray(); //new SelectList(city, "Cityid", "Cityname"); userlist.Countries = model.Countries; userlist.States = userlist.SelectedCountry != null?states.Where(x => x.country_id == userlist.SelectedCountry).ToList() : new List <CountriesDto>(); userlist.Cities = model.Cities; return(View(userlist)); } return(View(model)); }