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

            ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "AuthorName", book.AuthorID);
            ViewBag.TypeID = new SelectList(db.TypeBooks, "TypeID", "TypeName", book.TypeID);
            return View(book);
        }
예제 #2
0
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "AuthorName", book.AuthorID);
     ViewBag.TypeID = new SelectList(db.TypeBooks, "TypeID", "TypeName", book.TypeID);
     return View(book);
 }