What is Validation Summary?

The ValidationSummary helper displays an unordered list of all validation errors in the ModelState dictionary. It accepts a boolean value (i.e. true or false) and based on boolean value it display the errors. When boolean parameter value is true, it shows only model-level errors and excludes model property-level errors (i.e any errors that are associated with a specific model property). When Boolean value is false, it shows both model-level and property-level errors.
Suppose, you have the following lines of code somewhere in the controller action rendering a view:

ModelState.AddModelError("", "This is Model-level error!");
ModelState.AddModelError("Name", "This Model property-level error!");

In the first error there is no key to associate this error with a specific property. In the second error there is a key named as “Title” to associate this error for model property Title.

@Html.ValidationSummary(true) @*//shows model-level errors*@
@Html.ValidationSummary(false) @*//shows model-level and property-level errors*@

Hence, when boolean type parameter value is true then ValidationSummary will display only model-level errors and exclude property-level errors. It will display Model-level and property-level errors, when boolean type parameter value is false.

Tagged , . Bookmark the permalink.

Leave a Reply