Co-Authored By:
Thereof, what does ModelState IsValid mean?
ModelState. IsValid indicates if it was possible to bind the incoming values from the request to the model correctly and whether any explicitly specified validation rules were broken during the model binding process. In your example the, the model that is being bound is of class type Encaissement .
Additionally, why ModelState IsValid is false in MVC?
If any errors are found, they are added to the Errors collection in the property's ModelState. Also note that IsValid is false now. That's because an error exists; IsValid is false if any of the properties submitted have any error messages attached to them.
ModelState. Clear() is used to clear errors but it is also used to force the MVC engine to rebuild the model to be passed to your View. So call ModelState. Clear() right before you pass the model to your View.