public JsonResult Get() { List <Models.Country> countrylist = new List <Models.Country>(); SCountry sco = new SCountry(); List <Country> countries = sco.FindAll(); //var ret = countries.Select(x => new { x.Id, x.Name }).ToList(); foreach (Country country in countries) { countrylist.Add(new Models.Country() { CountryID = country.Id, CountryName = country.Name }); } return(new JsonResult { Data = countrylist, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult Get(string SelectedCountryId) { List <Models.Country> countrylist = new List <Models.Country>(); SCountry sco = new SCountry(); List <Country> countries = sco.FindAll(); Country countryr = sco.FindCountrybyId(int.Parse(SelectedCountryId)); Models.Country countrym = new Models.Country(); countrym.CountryID = countryr.Id; countrym.CountryName = countryr.Name; //var ret = countries.Select(x => new { x.Id, x.Name }).ToList(); foreach (Country country in countries) { //if (country.Id == countryr.Id) //{ countrylist.Add(new Models.Country() { CountryID = country.Id, CountryName = country.Name, //Selected = true }); //} //else //{ //countrylist.Add(new Models.Country() //{ // CountryID = country.Id, // CountryName = country.Name, // Selected = false //}); //} } //countrylist.Insert(0, countrym); return(this.Json(countrylist, JsonRequestBehavior.AllowGet)); //return new JsonResult { Data = countrylist, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }