What is the use of Html.ValidationSummary helper method in ASP.NET MVC?

 Posted by Sheonarayan on 10/25/2013 | Category: ASP.NET MVC Interview questions | Views: 6773 | Points: 40

The Html.ValidationSummary helper method is used to display all validation errors in the ModelState dictionary, either model property level or errors associated with ModelState.

Model Property level errors are errors that are set as an attributes of the property of the Model. eg


[StringLength(100, ErrorMessage="The Title must not be more than 100 characters long.")]
public string Title { get; set; }

In the above code, the Title field is a mandatory field and can only accept 100 characters.

The ModelState level errors are errors that are set by developer in the Controller by using below code snippet.

ModelState.AddModelError("", "There is an error!");

In this case, the error will be displayed in place of Validation summary like this

<div class="validation-summary-errors">

<li>There is an error!</li>

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response