[ASP. NET MVC] Html.validationsummary (BOOL)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.