public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryId,Name,Description,Content,CreateDate")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(await _context.Category.ToListAsync(), "Id", "Name", product.CategoryId); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CreateDate")] Category category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }