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]ASP.NET Core 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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Remote Validation

Starting with version 3, the ASP.NET MVC framework allows you to validate a form field on the server side without submitting the entire form to the server. This can be useful if it is necessary to validate a field that cannot be validated on the client side; for example, if you need to check whether or not a record with the same field value already exists in the database. Remote validation allows you to prevent the end-user from sending the web form to the server multiple times before the proper value is entered.

This topic describes how to add a remote validation functionality to the DevExpress ASP.NET MVC Data Editors.

To implement remote validation within DevExpress MVC Data Editors, you need to perform the following steps.

Expanded Remote validation requirements

JavaScript References

The remote validation mechanism requires the jquery-1.*.*.min.js, jquery.validate.min.js and jquery.validate.unobtrusive.min.js JavaScript references to be included in your layout page (or to certain views that contain validated forms). These libraries are available in the newly created ASP.NET MVC (vol. 3 or higher) project or via the Nuget Package Manager.

The code sample below demonstrates how to include the required JavaScript references (using the Razor View Engine in MVC 3).

Razor v2+ (which is used in MVC 4+) allows you to add the same script references in the following way.

Note

The JavaScript references should be added in the order they are specified in the code samples above.

 

Enable Unobtrusive JavaScript

Remote validation requires enabling unobtrusive JavaScript.

To enable unobtrusive JavaScript for all pages in your project, add the following keys to the Web.config file.

To enable unobtrusive JavaScript for a specific view only, add the following code to the required view.

View code (Razor):

 

Date Editor Requirements

The validated DevExpress ASP.NET MVC Data Editor should be bound to the data model field. To bind an editor to a model field, use the editor's Bind method and set the editor's Name property to the name of the corresponding data model field. You can also use strongly-typed Data Editors, which can be bound to model fields using a lambda expression.

The ASP.NET MVC Framework requires data editors to be inside of a <form> element that can be rendered with Html.BeginForm() in order to be validated.

Expanded Adding a validation action to the controller code

In the controller code, add an action method that will receive an object of the same type as the validated field. This action method should return true as JSON-formatted content for valid values. Any other response is considered false. If the method returns false, the validation error message appears. You can define the error message text in the Remote attribute ErrorMessage property as shown in the model code above. Refer to the Displaying Validation Error Messages article to learn more about displaying validation error messages.

The code sample below demonstrates how to create an action method that validates whether or not a user with the specified email address already exists.

Controller code:

Expanded Adding validation options to the model class

The remote validation is performed on the server side, by an action method in a controller, specified within the RemoteAttribute parameters. To define an action method and a controller that should perform remote validation, decorate a required model field with the RemoteAttribute attribute with the necessary parameters.

The code sample below illustrates how to validate the “Email” field in the "CheckIfExists" action of the "Home" controller.

Model code:

Expanded See Also

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