MVC: Validation – Remote

Using the Remote attribute to leverage JQuery’s validator.

MVC provides a flexible and powerful method for using logic external to the Model for enforcing business rules – the Remote attribute.
In this article, I will illustrate how to use an action method from a Controller to validate a Model’s attribute.

First, I’ll add the Remote attribute to the Model property on which I plan to execute external logic to validate the territory entered is one of the acceptable values – “OR.”

1-mvc-validation-remote

Next, I’ll implement the validation method called in the attribute – “ValidateTerritory()” located inside my Controller.

2-mvc-validation-remote

Now when I enter a value that isn’t one of the accepted territories, I get an error message.

3-mvc-validation-remote

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s