Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]ASP.NET WebForms Controls
 [Collapse]ASP.NET MVC Extensions
  [Expand]Product Information
  [Expand]Getting Started
  [Expand]Common Concepts
  [Expand]Grid View
  [Expand]Card View
  [Expand]Vertical Grid
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]HTML Editor
  [Expand]Image and Data Browsing
  [Expand]Docking and Popups
  [Expand]Navigation and Layout Extensions
  [Expand]File Management
  [Expand]Multi-Use Site Extensions
  [Expand]Charts
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Tree List
  [Collapse]Data Editor Extensions
    Editor List
    Main Features
   [Collapse]Common Concepts
     Binding Data Editors to Data
     Getting Editor Values
     Mask Editing
    [Collapse]Validation
      Validation Overview
      Model Validation
      Unobtrusive Client Validation
      jQuery Client Validation
      Built-in Validation
      Remote Validation
      Displaying Validation Error Messages
      Validating Dynamically Loaded Forms
     Accessibility Support
   [Expand]Editor Types
   [Expand]Strongly-Typed Editor Types
  [Expand]Report Extensions
  [Expand]SpellChecker
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Displaying Validation Error Messages

When editor validation fails, an error message can be displayed. You have the ability to use different approaches to display validation error messages.

DevExpress MVC Data Editors allow you to use the following ways to render placeholders for the validation error messages.

Expanded ValidationMessageFor Method

DevExpress MVC Data Editors can be seamlessly integrated into the standard ASP.NET MVC validation infrastructure, so you can use standard ASP.NET MVC ValidationMessageFor() method to generate the HTML markup for a validation error message for each data field that is represented by the specified expression.

The code sample below demonstrates how to use the ValidationMessageFor() method to render a placeholder for the validation error message.

You can see how a validation error message appears in the picture below.

Expanded ValidationSummary Method

You can use the standard ASP.NET MVC ValidationSummary method to render a placeholder for the list of validation error messages. The ValidationSummary() method returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.

Note

The standard ValidationSummary method doesn't allow you to render errors if you use the jQuery Client Validation approach. In this case, you can use the DevExpress ValidationSummary MVC Extension that renders jQuery Client Validation errors correctly.

The code sample below demonstrates how to use ValidationSummary method to render a placeholder for the validation error messages.

You can see how a summary of validation error appears messages in the picture below.

Expanded Editor Built-in Validation Error Messages Placeholder

The DevExpress MVC Editors have the ShowModelErrors property, which allows (when enabled) error messages to be automatically displayed within invalid editors when validation fails. Using a built-in error message placeholder allows you to flexibly control how errors should be displayed within editors by using settings exposed via the editor ValidationSettings property, such as ValidationSettings.ErrorDisplayMode.

The table below demonstrates how different ErrorDisplayMode property values affect validation error message appearance.

ErrorDisplayMode property value Description Image
ImageWithText An error message is represented by both an error image and error text.
ImageWithTooltip An error message is represented by an error image. The image's tooltip displays the error text.
Text An error message is represented by an error text only.
None A specific error frame is displayed near the editor.

The code sample below demonstrates how you can configure the TextBox extension to render the built-in validation error message placeholder.

You can see how the rendered validation message looks in the picture below.

Expanded DevExpress ValidationSummary MVC Extension

The DevExpress ValidationSummary extension allows you to summarize validation errors from multiple editors and then display them in a single block. This helps you to organize screen space more effectively if validation is required for several editors. See this topic to learn more about DevExpress ValidationSummary extension main features: ValidationSummary Main Features.

In order to show a validation error message in a DevExpress ValidationSummary extension you should do the following.

  1. Define the same ValidationGroup property value for all the validated editors and the ValidationSummary extension; if the ValidationSummarySettings.ValidationGroup property is not specified, the editor displays validation errors of the editors with an unspecified ValidationSettings.ValidationGroup property.
  2. Set the editor's ShowModelErrors property value to True;
  3. Set the editor's ValidationSettings.Display property value to Display.None.

The code sample below demonstrates how to use a DevExpress ValidationSummary extension and configure a TextBox extension in order to render a validation error message in a DevExpress ValidationSummary block.

You can see the rendered result in the picture below.

How would you rate this topic?​​​​​​​