пятница, 24 августа 2012 г.

ASP.NET MVC 3 Self-validating Model’s client side validation is not working

Today I realized that the Client Side validation is not exercising my rules associated with my self-validating objects. My models correctly implemented the IValidatableObject and its Validate method, so I tried searching the web to find out how I could resolve this issue.
As you may already know the IValidatableObject.Validate method is a server side validation, let’s have a look at an example of this method’s implementation below:
If you have returned the error message just like the way I did, the message will be associated to the class and not a specific property, so the underlying .NET Validation engine cannot show the message next to the property in the View. In order to solve this issue, you need to pass the name of the properties along with the error message through:
Then the client validation engine will show the error message next to the property field:

Комментариев нет: