Html.ValidationSummary:-

ValidationSummary helper is used to display the list of validation error message stored in “ModelState” dictionary.

ModelState – it is one of the properties of the ‘Controller’ of type dictionary. It keeps all validation error message based on the validation rule applied on Model object.

Example:

Code:ModelState.AddModelError("", "This error message is from model level");

View:@Html.ValidationMessage()

Render:

            
<div 
  class="validation-summary-errors">
<ul>
<li>This error message is from model level</li>
</ul>
</div>
            
            

Comments: This error message will listed while calling the validation summary without any specific key


Code:ModelState.AddModelError("EmployeeName", "Value cannot be null for Employee Name field!");

View:@Html.ValidationMessage("EmployeeName")

Render:

            
<divclass="validation-summary-errors">
<ul>
<li>Value cannot be null for Employee Name  field!</li>
</ul>
</div>
            
            

Comments: Validation summary will list with model state with specific key mention.

In general validation is applied on top of model object based on the Data annotation and these validation error message will be stored in ModelState property with key is same as property name of the model object.