Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
am trying to implement custom client side validation, and i was wondering can i access the value to validate in the GetClientValidationRules just like the value in IsValid??

thanks in advance
Posted

1 solution

I ended up using an ajax call inside the javascript validation file where I can access the value to be validated as follows:
JavaScript
$.validator.addMethod("custom-validation-name", function (value, element, params) {
    var valid = false;
    $.ajax({
        url: "/Controller/Action",
        type: "Get",
        async:false,
        data: { value-to-validate: value },
        success: function (data) {
            valid = parseInt(data) > 0;
        }
    });

    return valid;
});

Create an action in the controller to check weather the value is valid or not
make sure that the async option is set to false
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900