Client-side Custom Annotation Validation Not Working
I am trying to get client-side validation working with custom annotations in an ASP.NET MVC app. Sorry for the somewhat lengthy post. Here is the custom attribute: public class Cu
Solution 1:
I finally got this working! I decided not to try to use the "convenience" addMinMax adapter, but instead write a custom adapter. Here is the updated customValidation.js (everything else stays the same):
(function ($) {
if ($.validator && $.validator.unobtrusive) {
$.validator.unobtrusive.adapters.add('customstringlength', ['min', 'max'], function(options) {
options.rules['customstringlength'] = {
min: options.params.min,
max: options.params.max,
};
options.messages['customstringlength'] = options.message;
});
$.validator.addMethod('customstringlength', function (value, element, params) {
if (value) {
if (value.length < params.min || value.length > params.max) {
return false;
}
}
return true;
});
}
}(jQuery));
Post a Comment for "Client-side Custom Annotation Validation Not Working"