예제 #1
0
        public async Task <IActionResult> Create([Bind("AuthorId,Name")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
        public async Task <IActionResult> Create([Bind("BookId,Title,Description,PublishedOn,AuthorId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Set <Author>(), "AuthorId", "Name", book.AuthorId);
            return(View(book));
        }