// GET: Books/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Book book = db.Books.Find(id); if (book == null) { return(HttpNotFound()); } var model = new BookCreateModelView(); model.BookId = book.BookId; model.Title = book.Title; model.Author = book.Author; model.Description = book.Description; model.CategoryId = book.CategoryId; model.Date = book.Date; model.ISBN = book.ISBN; model.Available = book.Available; model.Categories = db.Categories.Select(c => new SelectListItem { Text = c.Name, Value = c.CategoryId.ToString() }); return(View(model)); //return View(book); }
// GET: Books/Create public ActionResult Create() { var model = new BookCreateModelView(); model.Categories = db.Categories.Select(c => new SelectListItem { Text = c.Name, Value = c.CategoryId.ToString() }); model.Date = DateTime.Now; return(View(model)); }