asp.net-mvc-5custom-validatorsfoolproof-validationvalidationmessage

MVC Foolproof Validation multiple error messages


I am building some custom validations for a ViewModel and have a question in regards to having multiple error messages.

I am wanting to create a custom validation on a string attribute. Depending on the values being compared, I wish to output different validation messages.

Is this possible, or do I need to create a different custom validation for each message that is displayed?

Thanks in advance


Solution

  • Yes, it is possible to implement custom validations on properties of model. Please refer this tutorial to create custom validation attribute to do the work as you need, where you need to write your own jquery validation script for client side validation in MVC framework way if you use IClientValidatable which is also explained in the same.