I have an unobtrusive validation defined on a class which validates that the number entered is a valid number in the database. I'd prefer not to use a Remote attribute, as it ties me to a specific controller instead of a service, and the class is actually in a library that is not in the MVC Web application. I'd like to use JavaScript as follows:
$.validator.addMethod("validid", function (value, element) {
$.ajax({
url: 'mypage.html',
success: function(){
return true;
},
error: function(){
return false;
}
});
});
$.validator.unobtrusive.adapters.addBool("validid");
I know that I can use an addsingleval and pass in all of the valid IDs in an array, but I would prefer the method to call a service and validate the sing value on the server instead of passing in all possible values in the database. I do recognize the problem of making an asynchronous call and trying to return the value in the function that has already completed, but I'm wondering if there's some other way to make this work.