I have a method that have [FromBody]
parameter but it ModelState.IsValid
keep returning true
if values are longer than they limited with MaxLength
attributes in the mapped object.
public class AddUserMsg
{
[MaxLength(10)]
public string name;
}
[HttpPost("[action]")]
public IActionResult AddUser([FromBody] AddUserMsg msg)
{
// Always true even if the name is longer than 10 symbols
if (ModelState.IsValid)
{
}
}
I thought it suppose to validate posted data. Any ideas why it does not?