0

I have defined something like this:

@Html.TextBoxFor(t => t.NumberOfThings, new {style = "width: 10%", @class = "form-control"})
@Html.ValidationMessageFor(t => t.NumberOfThings)

and

[Range(1, int.MaxValue, ErrorMessage = "The value entered must be bigger than zero.")]
public int NumberOfThings{ get; set; }

But even if the data entered is in correct range, I am still seeing the error messgae label. Is there more things I should do?

Bohn
  • 26,091
  • 61
  • 167
  • 254
  • What is the data annotation for NumberOfThings? – Carlos Figueroa Jun 08 '16 at 16:27
  • It is in the question. Do you need something else? – Bohn Jun 08 '16 at 16:28
  • It should work. Chances are you may have to update the versions of jquery validation and jquery validation unobtrusive. There's a question with a similar problem here: http://stackoverflow.com/questions/14889431/client-side-validation-trips-on-dataannotation-range-attribute/14989703#14989703 – Carlos Figueroa Jun 08 '16 at 16:37

1 Answers1

0

Have you tried setting the type of the range?

[Range(typeof(int), 1, int.MaxValue, ErrorMessage = "The value entered must be bigger than zero.")]

It may also be to do with using int.MaxValue - you may need to write a CustomRange to handle using this as the values entered must be constants.

stephyness
  • 29
  • 5
  • Surely int.MaxValue will not be an issue here since it is clearly a constant. Regarding using typeof(int) to make your value 1 explicity an int, could you explain why this would need to be done in this particular context? I would very much hope here that .Net would be clever enough to cast to constant implicitly, but it would be interesting to know if it's not able to infer this. – Peter David Carter Nov 12 '19 at 19:26