public async Task <IActionResult> Create([Bind("Priority,Type,Id,Title,Description,Status")] todoModels.Task task) { if (ModelState.IsValid) { _context.Add(task); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(task)); }
public IActionResult Create(Task newTask) { using (var db = new TasksDbContext()) { if (!ModelState.IsValid) { TempData["ErrorMessage"] = "The title and comment are required!"; return(View()); } db.Add(newTask); db.SaveChanges(); return(RedirectToAction("Index")); } }