Summary
The ValidationSummary is a htmlhelper extension method that returns an unordered list (UL element) of the validation message in the System.Web.Mvc.ModelStateDictionary (that is, the Modelstate) object.
An example
@Html. ValidationSummary (True): tells the helper method to exclude property-level errors. In other words, it tells the ValidationSummary method to show only errors in modelstate that are related to the model itself , not those related to the specific model properties . False, all errors for the current model are displayed.
Defined
// //Summary://Returns an unordered list (UL element) that validates messages in the System.Web.Mvc.ModelStateDictionary object, and optionally displays only model-level errors. // //Parameters://HtmlHelper://This method extends the HTML helper instance. // //excludepropertyerrors://true indicates that the digest displays only model-level errors; false means that the summary displays all errors. // //return Result://A string that contains an unordered list of validation messages (UL elements). Public StaticMvchtmlstring ValidationSummary ( ThisHtmlHelper HtmlHelper,BOOLExcludepropertyerrors);
True indicates that the digest displays only model-level errors; false means that the summary displays all errors.
Test
Public actionresult Test () { Modelstate.addmodelerror ("" " This is an error "); Modelstate.addmodelerror ("Name"" nameless is famous, but must be written " ); return View (); }
<div> @Html. ValidationSummary (true) </div>
Results
If modified to False
In both cases, it is also stated that
True indicates that the digest displays only model-level errors; false means that the summary displays all errors.
Summarize
The first is a model-level error because the error in the code does not provide a key (or a null key) associated with a particular property. The second is the error associated with the Name property, so in the case of true, it is not displayed unless the parameter name is deleted, or it is changed to false.
[ASP. NET MVC] Html.validationsummary (BOOL)