Example #1
0
        public ActionResult GetCities(string id)
        {
            citydata = new CityData();
            citydata.AddCity(new City {
                CityID = 1, Name = "1111111", StateID = 1
            });
            citydata.AddCity(new City {
                CityID = 2, Name = "2222222", StateID = 1
            });
            citydata.AddCity(new City {
                CityID = 3, Name = "33333333", StateID = 2
            });
            citydata.AddCity(new City {
                CityID = 4, Name = "44444444", StateID = 2
            });

            IList <City> citylist = new List <City>();

            foreach (var item in citydata.GetList())
            {
                if (item.StateID.ToString().Equals(id))
                {
                    citylist.Add(item);
                }
            }
            var json = new JavaScriptSerializer().Serialize(citylist);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }