I get stuck on the ModelState.IsValid. I try to solve them from the other example, but it not worked. Could you guy help on me please?
This is my controller:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("DepartmentId,DepartmentName,LocationId")] Department department)
{
if (ModelState.IsValid)
{
_context.Add(department);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["LocationId"] = new SelectList(_context.Set<Location>(), "LocationId", "LocationId", department.LocationId);
return View(department);
}
Hi , Please use this code it will work.