Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Html.ValidationSummary() has a value

How can I check if Html.ValidationSummary() has any errors?

Ultimate result required:

<% if(I_HAVE_ERRORS) {%> <div><%= Html.ValidationSummary() %></div> <%}%> 

In other words, how can I determine "I_HAVE_ERRORS"?

like image 669
stoic Avatar asked Nov 05 '10 11:11

stoic


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.

How do you use ValidationSummary?

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.

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?

AddModelError() method. The ValidationSummary() method will automatically display all the error messages added in the ModelState . Thus, you can use the ValidationSummary helper method to display error messages.


1 Answers

<%if (!Html.ViewData.ModelState.IsValid){%> 
like image 108
stoic Avatar answered Nov 09 '22 17:11

stoic