我如何使用长类型的DataAnnotation范围?(How could I use Range of DataAnnotation with long type?)

编程入门 行业动态 更新时间:2024-10-21 10:30:00
如何使用长类型的DataAnnotation范围?(How could I use Range of DataAnnotation with long type?)

我正在尝试使用DataAnnotation创建Range以键入long数字,但它总是抛出异常,我无法修复它。 我认为问题是因为我需要键入一个大数字作为示例07608800000070然后它抛出异常。

我怎么能解决这个问题?

我尝试着

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

例外

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

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

最满意答案

我遇到了同样的问题,这是由于jQuery验证中的一个错误 。 他们声称这是固定的,但我认为这又被打破了。 我使用了一种解决方法 (或修复)。

发生的事情是客户端允许的数字大于范围,因为范围JS代码有一个错误,因此当该大数字到达服务器时,服务器端验证由于此错误而中断:

mscorlib.dll中发生了'System.OverflowException'类型的第一次机会异常

确保您的范围的最大值可以适合长(或您使用的任何数据类型),否则即使客户端验证工作,如果它不适合它,您仍将在服务器端获得错误。

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.

更多推荐

本文发布于:2023-08-01 14:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1359188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   类型   DataAnnotation   type   long

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!