in Education by
What is Validation Summary in MVC?

1 Answer

0 votes
by

The ValidationSummary helper method generates an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.

 

The ValidationSummary can be used to display all the error messages for all the fields. It can also be used to display custom error messages. The following figure shows how ValidationSummary displays the error messages.

 
Most Asked ASP.NET MVC Interview Questions and Answers
 

ValidationSummary() Signature

 

MvcHtmlStringValidateMessage(bool excludePropertyErrors, string message, object htmlAttributes)

 

Display field level error messages using ValidationSummary

 

By default, ValidationSummary filters out field level error messages. If you want to display field level error messages as a summary then specify excludePropertyErrors = false.

 

Example - ValidationSummary to display field errors

 

@Html.ValidationSummary(false, "", new { @class = "text-danger" })

 

So now, the following Edit view will display error messages as a summary at the top. Please make sure that you don't have a ValidationMessageFor method for each of the fields.

 
Most Asked ASP.NET MVC Interview Questions and Answers

Related questions

0 votes
0 votes
    What are the methods of handling an Error in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is difference between MVC and Web Forms?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What are the Folders in MVC application solutions?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is Database First Approach in MVC using Entity Framework?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is Bundling and Minification in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
0 votes
    What is Razor View Engine in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
0 votes
    Explain the concept of MVC Scaffolding?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    Explain the need of display mode in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
0 votes
    How do you implement Forms authentication in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
...