2

E.g. I have the following model:

public class MyModel {
public Line[] Lines{get;set;}
}

public class Line {
public int Quantity{get;set;}
public int MaxQuantity{get;set;}
}

The "Quantity" field should be less than "MaxQuantity" so I tried to use "LessThanOrEqualTo" validation attribute:

public class Line {
[LessThanOrEqualTo("MaxQuantity")]
public int Quantity{get;set;}
public int MaxQuantity{get;set;}
}

But it does not work on client side because of wrong dependent property name I believe:

<input type="number" value="1" name="Lines[0].Quantity" data-val-is-passonnull="False" data-val-is-operator="LessThanOrEqualTo" data-val-is-dependentproperty="MaxQuantity" data-val-is="Quantity must be less than or equal to MaxQuantity." data-val="true">
<input type="hidden" value="1" name="Lines[0].MaxQuantity">

You can see that "data-val-is-dependentproperty="MaxQuantity"" but real input name is "Lines[0].MaxQuantity""

Is there any way to fix this?

Andrei
  • 4,237
  • 3
  • 25
  • 31

1 Answers1

0

Have you included mvcfoolproof.unobtrusive.min.js in your view or your master page? Have you checked that the script is loaded before your code is using it?

With my Foolproof Nuget installation, it was placed in "Client Scripts" folder from Foolproof Nuget installation.

cpoDesign
  • 8,953
  • 13
  • 62
  • 106
Angel Dinev
  • 399
  • 4
  • 13