public async Task <IActionResult> Create([Bind("Id,Name,Brand,Model")] Printer printer) { if (ModelState.IsValid) { _context.Add(printer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(printer)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
[HttpPost] //post method public async Task <IActionResult> Create([Bind("Id,Name")] Book book) { if (ModelState.IsValid) { _db.Add(book); //add data to Book table await _db.SaveChangesAsync(); //wait for database response return(RedirectToAction(nameof(Index))); // redirect to index } return(View(book)); }
public async Task <IActionResult> Create([Bind("Id, Name, Brand, Model")] Printer printer) { if (ModelState.IsValid) { _db.Add(printer); //add data to Printer table await _db.SaveChangesAsync(); //wait for database response return(RedirectToAction(nameof(Index))); // redirect to index } return(View(printer)); }