Exemplo n.º 1
0
        public ActionResult ModifyCity(string id)
        {
            string strErrText;

            //生成Model数据
            DDSystem city = new DDSystem();
            City     data = city.LoadCity(long.Parse(id), LoginAccountId, LoginStaffName, out strErrText);

            if (data == null)
            {
                throw new Exception(strErrText);
            }

            CityViewModel model = new CityViewModel();

            model.Id           = data.Id;
            model.Name         = data.Name;
            model.CountryName  = data.CountryName;
            model.ProvinceName = data.ProvinceName;
            model.Remark       = data.Remark;

            //生成国家下拉列表项
            DDSystem       dd          = new DDSystem();
            List <Country> listCountry = dd.LoadCountrys(LoginAccountId, LoginStaffName, out strErrText);

            if (listCountry == null)
            {
                throw new Exception(strErrText);
            }
            List <SelectListItem> selectListCountry = new List <SelectListItem>();

            selectListCountry.Add(new SelectListItem {
                Text = string.Empty, Value = string.Empty
            });
            selectListCountry.AddRange(from c in listCountry
                                       select new SelectListItem
            {
                Text  = c.Name,
                Value = c.Name
            });
            ViewData["Countries"] = new SelectList(selectListCountry, "Value", "Text", model.CountryName);

            //生成空的省份下拉列表项
            List <Province> listState = null;

            if (!string.IsNullOrEmpty(model.CountryName))
            {
                listState = dd.LoadProvincesByCountry(model.CountryName, LoginAccountId, LoginStaffName, out strErrText);
                if (listState == null)
                {
                    throw new Exception(strErrText);
                }
            }
            else
            {
                listState = new List <Province>();
            }
            List <SelectListItem> selectListState = new List <SelectListItem>();

            selectListState.Add(new SelectListItem {
                Text = string.Empty, Value = string.Empty
            });
            selectListState.AddRange(from s in listState
                                     select new SelectListItem
            {
                Text  = s.Name,
                Value = s.Name
            });
            ViewData["States"] = new SelectList(selectListState, "Value", "Text", model.ProvinceName);

            return(View(model));
        }