// GET: Class/Create public ActionResult Create() { BatchList Batchlist = new BatchList(); //Khởi tạo biếm có giá trị là class được khai báo trong models/batch LevelList Levellist = new LevelList(); List <batch> obj = Batchlist.ListAll(); //Gọi hàm listall khai báo trong class trong models lấy ra danh sách batch List <level> obj1 = Levellist.ListAll(); ViewBag.batchCode = new SelectList(obj, "code", "name"); //Đưa viewBag vào view ViewBag.levelCode = new SelectList(obj1, "code", "name"); return(View()); }
public ActionResult Create(_class cl) { //Phải khởi tạo lại viewBag mới lấy được dữ liệu BatchList Batchlist = new BatchList(); LevelList Levellist = new LevelList(); List <batch> obj = Batchlist.ListAll(); List <level> obj1 = Levellist.ListAll(); ViewBag.batchCode = new SelectList(obj, "code", "name"); ViewBag.levelCode = new SelectList(obj1, "code", "name"); try { // TODO: Add insert logic here ClassList Classlist = new ClassList(); Classlist.addClass(cl); //Gọi đến hàm addClass trong class ClassList trong models return(RedirectToAction("Index")); } catch { return(View()); } }