예제 #1
0
        public ActionResult Create(Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Street", student.LocationId);
            ViewBag.SchoolId = new SelectList(db.Schools, "SchoolId", "Name", student.SchoolId);
            return View(student);
        }
예제 #2
0
 public ActionResult Edit(Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Street", student.LocationId);
     ViewBag.SchoolId = new SelectList(db.Schools, "SchoolId", "Name", student.SchoolId);
     return View(student);
 }