public async Task <IActionResult> Create(StudentCreateViewModel student) { if (ModelState.IsValid) { _context.Students.Add(student.MapToDbModel()); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("FirstName,LastName,Age,Address")] StudentCreateViewModel student) { //if(student.FirstName[0] != student.FirstName.ToUpper()[0]) //{ // ModelState.AddModelError(nameof(student.FirstName), "Names should begin with capital letter"); //} if (ModelState.IsValid) { _context.Add(student.MapToDbModel()); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }