public ActionResult Edit(int id) { WN_WarningSett entity = null; using (MBREntities db = new MBREntities()) { entity = db.WN_WarningSett.Find(id); } List <SelectListItem> WarningLevelList = new List <SelectListItem>(); DATADICTIONARYService DATADICTIONARYService = new DATADICTIONARYService(); var dicValues = DATADICTIONARYService.GetDicValuesByCode("WarningLevel"); if (dicValues != null) { foreach (var item in dicValues) { bool selected = item.Key.Equals((entity.WarningLevel ?? 0).ToString()); WarningLevelList.Add(new SelectListItem() { Text = item.Value, Value = item.Key, Selected = selected }); } } ViewBag.WarningLevel = WarningLevelList; return(View(entity)); }
public ActionResult Create() { List <SelectListItem> WarningLevelList = new List <SelectListItem>(); DATADICTIONARYService DATADICTIONARYService = new DATADICTIONARYService(); var dicValues = DATADICTIONARYService.GetDicValuesByCode("WarningLevel"); if (dicValues != null) { foreach (var item in dicValues) { WarningLevelList.Add(new SelectListItem() { Text = item.Value, Value = item.Key }); } } ViewBag.WarningLevel = WarningLevelList; return(View()); }
public JsonResult GetDicValuesByCode(string code) { DATADICTIONARYService DATADICTIONARYService = new DATADICTIONARYService(); return(Json(DATADICTIONARYService.GetDicValuesByCode(code), JsonRequestBehavior.AllowGet)); }