Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.ValidationSummary(true) - What's the true do?

I have code that contains:

@Html.ValidationSummary(true)

I looked at the MSDN site and still can't see what setting "true" does? What I notice is that when I have validation messages that are for fields then it still creates a validation summary DIV that's empty.

Is there a way to supress the creating of the summary DIVs as they don't show anything when for example my field is a duplicate.

like image 394
Samantha J T Star Avatar asked Dec 26 '11 11:12

Samantha J T Star


People also ask

What is HTML ValidationSummary true?

The ValidationSummary() extension method displays a summary of all validation errors on a web page as an unordered list element. It can also be used to display custom error messages.

What is ValidationSummary?

The ValidationSummary class is used to summarize the error messages from all validators on a Web page in a single location. You can summarize the error messages from a group of validators on a Web page by assigning the ValidationSummary control to a validation group by setting the ValidationGroup property.

How do I create a custom error message in ValidationSummary?

To display a custom error message, first of all, you need to add custom errors into ModelState in the appropriate action method. As you can see in the above code, we have added a custom error message using the ModelState. AddModelError() method.

How do you show custom validator error message in ValidationSummary?

In order for the Validator 's error message to display in the ValidationSummary , you need to set the Validator s Display="none" . I also set Text="" .


1 Answers

You can specify error messages against the properties or against the model. Those specified against the model are displayed using the validationsummary().

The bool property indicates if you would like to display the validation summary error messages at the same time as displaying the property error messages. If you choose not to then the property error messages will be displayed to the user first. Then, when the user has resolved all of those error messages, the summary error messages will be displayed after.

If the bool parameter is true then only model-level errors are displayed. If the parameter is false then all errors are shown.

like image 159
Dangerous Avatar answered Oct 20 '22 16:10

Dangerous