I have seen many reports about IsValid that are always true, but none of them have helped me solve this problem. I also see this problem in ASP.NET 4 using MVC5. Itβs so clear that Iβm missing a step somewhere.
Controller Method:
public IHttpActionResult Post([FromBody]ValuesObject value) { if (ModelState.IsValid) { return Json(value); } else { return Json(ModelState); } }
ValuesObject Class:
public class ValuesObject { [Required] public string Name; [Range(10, 100, ErrorMessage = "This isn't right")] public int Age; }
Body POST:
{ Age: 1 }
ModelState.IsValid - true.
But I would expect both Required and Range checks to fail.
What am I missing?
Thanks,
Kevin
retsvek
source share