-1

I try to use LessThanOrEqualTo from Foolproof version 0.9.4518 compare and validate int from another property, and it is not working.

however, it works for datetime format just like the example.

Here is my code:

model:

public partial class TryFoolProof {
    public int max { get; set;}

    [LessThanOrEqualTo("max")]
    public int? min{ get; set; }
}

I have the script file included in the view:(somehow, NuGet didnt include)

<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script src="~/Scripts/mvcfoolproof.unobtrusive.min.js"></script>
<script src="~/Scripts/MvcFoolproofJQueryValidation.min.js"></script>
<script src="~/Scripts/MvcFoolproofValidation.min.js"></script>

here is the error:

mvcfoolproof.unobtrusive.min.js:1 Uncaught TypeError: Cannot read property 'addMethod' of undefined
    at mvcfoolproof.unobtrusive.min.js:1
    at mvcfoolproof.unobtrusive.min.js:1
MvcFoolproofJQueryValidation.min.js:1 Uncaught TypeError: Cannot read property 'addMethod' of undefined
    at MvcFoolproofJQueryValidation.min.js:1
MvcFoolproofValidation.min.js:1 Uncaught ReferenceError: Sys is not defined
    at MvcFoolproofValidation.min.js:1

so how can I get it work for int?

Thanks

user228
  • 67
  • 2
  • 10

1 Answers1

0

The scripts needed for client side validation using foolproof are, in order

jquery-{version}.js
jquery.validate.js
jquery.validate.unobtrusive.js
mvcfoolproof.unobtrusive.js

and you need to delete /MvcFoolproofJQueryValidation.min.js and MvcFoolproofValidation.min.js

In particular, you did not include jquery.validate.js so there is no validator to add the rules to.

  • I tried rearrange the order for the js file. still no luck :(. The problem is LessThanOrEqualTo works for DateTime format, but for int. – user228 Jan 27 '17 at 14:36
  • It works fine. And you cannot change your original question and invalidate my answer and I have rolled back your changes (although you still had the `MvcFoolproofJQueryValidation` which needed to be deleted). I can only assume you did not follow the instructions or you have other mistakes as well, but the error message in the question is clear - _Cannot read property 'addMethod' of undefined_ is because the `$.validator` is `undefined` because you did not include the jquery.validate.js file. –  Jan 27 '17 at 20:50
  • Found the problem. It was used wrong model attribute. after fix that everything works just fine. – user228 Feb 09 '17 at 22:33
  • That has nothing to do with your question which is about the error you were getting, and my answer is correct for your question! –  Feb 09 '17 at 22:37