コード例 #1
0
        public ActionResult States()
        {
            var s = serviceState.GetMany().ToList();
            List <StateViewModel> liste = new List <StateViewModel>();

            foreach (var item in s)
            {
                liste.Add(
                    new StateViewModel
                {
                    StateID   = item.StateID,
                    StateName = item.StateName,

                    Country = serviceCountry.GetById(item.CountryId).CountryName
                });
            }

            return(View(liste));
        }
コード例 #2
0
        public JsonResult getstate(int id)
        {
            var states = serviceState.GetMany().Where(x => x.CountryId == id).ToList();
            List <SelectListItem> listates = new List <SelectListItem>();

            listates.Add(new SelectListItem {
                Text = "--Select State--", Value = "0"
            });
            if (states != null)
            {
                foreach (var x in states)
                {
                    listates.Add(new SelectListItem {
                        Text = x.StateName, Value = x.StateID.ToString()
                    });
                }
            }


            return(Json(new SelectList(listates, "Value", "Text", JsonRequestBehavior.AllowGet)));
        }