When I set value from server side to prop has a validation attribute "MaxLength", the application not throw exception.
public class Student
{
public Guid Id { get; set; }
[MaxLength(40,ErrorMessage ="too long")]
public string Name { get; set; }
}
[HttpPost("AddStudent")]
public IActionResult AddStudent()
{
string studentName = System.IO.File.ReadAllText(@"C:\StudentName.txt");
Student student = new Student()
{
Id = Guid.NewGuid(),
Name = studentName, // Name larger than 40 char
};
//Add student to DB
return Ok();
}
I expect throwing exception directly while I set not valid value