0

I'm trying to create Range with DataAnnotation to type long number but it always throws an exception and I can't fix it. I think the problem is because I need to type a big number as an example 07608800000070 then it throws the exception.

How could I fix this ?

I'm trying

[Range(minimum: 1, maximum: 999999999999999, ErrorMessage = "Type the Parcel ID")]
public long parcelID  {get;set;}

Exception

A first chance exception of type 'System.OverflowException' occurred in mscorlib.dll
FernandoPaiva
  • 4,410
  • 13
  • 59
  • 118
  • You could try specifying the data type explicitly: `[Range(typeof(long), 1, 999999999999999, ErrorMessage = "Type the Parcel ID")]`. – Keyur PATEL Aug 31 '17 at 03:36

2 Answers2

1

I have had the same issue and this is due to a bug in jQuery Validation. They claim it was fixed but I think this is broken again. There is a workaround (or a fix) that I used.

What is happening is that the client side is allowing a number bigger than the range, because the range JS code has a bug, and thus when that big number arrives at the server, the server side validation breaks due to this error:

A first chance exception of type 'System.OverflowException' occurred in mscorlib.dll

Make sure your range's max value can fit into a long (or whatever datatype you use) otherwise even if client side validation was to work, you will still get the error on the server side if it cannot fit into it.

CodingYoshi
  • 25,467
  • 4
  • 62
  • 64
  • @FernandoPaiva please note that if you are using the workaround and you also have a miniified version of the jquery validation, you would need to either include the fix in the minified version (this is what i did) or create another minified file from the file with the fix (i dont know how to do this). If you do not use the minified version, then disregard this comment. – CodingYoshi Aug 31 '17 at 16:30
0

Can't make the client side validation work. I need a fix or workaround.

This is how i use range data annotation attribute:

[Range(1, int.MaxValue, ErrorMessage = "Geçerli bir tam sayı değer yazınız!")]
Ozan BAYRAM
  • 2,780
  • 1
  • 28
  • 35