Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the ValidationSummary show up even though the ModelState is valid?

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!

like image 485
Øyvind Avatar asked Aug 27 '11 20:08

Øyvind


People also ask

Why is ModelState false?

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.

Why is ModelState not valid MVC?

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)

What exactly does ModelState dot is valid do?

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 .


1 Answers

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!

like image 186
Øyvind Avatar answered Sep 22 '22 20:09

Øyvind