Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.ValidationSummary(false, "message") is always showing, even on page load

I am using client side validation and I would like the message below to show only when I have an error. I am trying to use this a general error in case any field is invalid.
Currently

"* denotes required field"

is always showing even before validation.

<%: Html.ValidationSummary(false, "* denotes required field.")%> 

I am using model binding to perform validation on client side and MVC.

like image 755
MondayPaper Avatar asked Nov 12 '10 16:11

MondayPaper


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 to show Validation message in c#?

ValidationSummary() helper is called immediately above the HTML form. This helper is used to display a list of validation error messages. The Html. ValidationSummary() helper renders the errors in a bulleted list.

How to add Validation summary in ASP net?

ValidationSummary control Syntax :Step 1 – Open Visual Studio –> Create a new empty Web application. Step 2 – Create a new web form and design a web form as shown in below screen. Step 3 – Drag and drop ValidationSummary control from Toolbox. List of Properties of ValidationSummary control.


2 Answers

If you use a developer tool in your browser to inspect the validation summary text you'll see that it has the class validation-summary-valid when it is clear but validation-summary-errors when there are form errors.

Therefore, just create a css rule as follows;

.validation-summary-valid {     display:none; } 

and all should be good.

like image 139
Ryan O'Neill Avatar answered Sep 21 '22 11:09

Ryan O'Neill


I think the issue is the fact the Html.ValidationSummary has to appear before the Html.BeginForm otherwise the message is always displayed.

like image 43
Mark P Avatar answered Sep 21 '22 11:09

Mark P