I have a view with @Html.ValidationSummary("Please check the following errors:") at the top of a form. The text "Please check the following errors:" is always rendered, whether or not the model state is valid (I have verified the model state both in the view and in the controller).
Can anyone point me to why this is happening? I feel like I'm missing something pretty basic here - but I'm stumped!
That's because an error exists; ModelState. IsValid is false if any of the properties submitted have any error messages attached to them. What all of this means is that by setting up the validation in this manner, we allow MVC to just work the way it was designed.
You get Model state not valid error when the server side validation of the model property has failed. So go to your action where you will find the following if condition that checks model state is valid: if (ModelState. IsValid)
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 model that is being bound is of class type Encaissement .
Uh - I just realised why. It was because I'd removed the default styles for the validation summary! Adding this back in solved my issue:
.validation-summary-valid
{
display: none;
}
D'oh!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With