// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                ViewData["PublisherID"] = new SelectList(_context.Set <Publisher>(), "ID", "PublisherName");
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            book = await _context.book.FirstOrDefaultAsync(m => m.ID == id);

            if (book == null)
            {
                return(NotFound());
            }
            ViewData["PublisherID"] = new SelectList(_context.Set <Publisher>(), "ID", "PublisherName");
            return(Page());
        }