I’m working on a school management system (ASP.NET MVC + MySQL) and need to implement update functionality for teacher records with robust validation. Here’s where I’m stuck:
Current Implementation
Server-Side (API Controller)
[HttpPut]
[Route("api/TeacherPage/UpdateTeacher")]
public IHttpActionResult UpdateTeacher([FromBody] Teacher teacher)
{
// Manual validation
if (string.IsNullOrEmpty(teacher.TeacherFname))
return BadRequest("Teacher name is required.");
if (teacher.HireDate > DateTime.Now)
return BadRequest("Hire date cannot be in the future.");
// ... database update logic
}
Client-Side (Edit.cshtml)
@model Teacher
Specific Problems
[Required]
annotations)?PUT
(full updates) or PATCH
(partial updates) for better REST compliance?What I’ve Tried
[Required]
to Teacher.cs
properties, but client-side validation doesn’t trigger for AJAX.ModelState.IsValid
in the controller, but it’s always true
for JSON payloads.Environment: