Skip to content

Instantly share code, notes, and snippets.

Last active April 26, 2018 20:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public async Task<IActionResult> Create([Bind("Id,Name,UserId")] Category category)
ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", category.UserId);
// If ModelState isn't valid, return to view immediately
if (!ModelState.IsValid)
return View(category);
// Add category, save changes and redirect to Category/Index - Categories List page
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment