示例#1
0
        public async Task <IActionResult> Create(BooksCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Book book = new Book
                {
                    Price  = model.Price,
                    ISBN   = model.ISBN,
                    Author = model.Author,
                    Pages  = model.Pages,
                    Title  = model.Title
                };

                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
示例#2
0
        // GET: Books/Create
        public IActionResult Create()
        {
            BooksCreateViewModel model = new BooksCreateViewModel();

            return(View(model));
        }