// GET: TRAMXEs/Create public ActionResult Create() { ILoaiXeService loaiXeService = new LoaiXeService(); IList <LOAIXE> loaiXeList = loaiXeService.GetAll(); List <SelectListItem> listItems = new List <SelectListItem>(); for (int i = 0; i < loaiXeList.Count; i++) { listItems.Add(new SelectListItem { Text = loaiXeList[i].TenLoai, Value = loaiXeList[i].MaLoai.ToString() }); } ViewBag.listItems = listItems; return(View()); }
// GET: TRAMXEs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //TRAMXE tRAMXE = db.TRAMXEs.Find(id); IList <XE> xE = service.Detail(id); if (xE == null) { return(HttpNotFound()); } ILoaiXeService loaiXeService = new LoaiXeService(); IList <LOAIXE> loaiXeList = loaiXeService.GetAll(); List <SelectListItem> listItems = new List <SelectListItem>(); for (int i = 0; i < loaiXeList.Count; i++) { if (xE[0].LoaiXe == loaiXeList[i].MaLoai) { listItems.Add(new SelectListItem { Text = loaiXeList[i].TenLoai, Value = loaiXeList[i].MaLoai.ToString(), Selected = true }); } else { listItems.Add(new SelectListItem { Text = loaiXeList[i].TenLoai, Value = loaiXeList[i].MaLoai.ToString() }); } } ViewBag.listItems = listItems; return(View(xE[0])); }