Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 25, 2012 01:48 PM by francesco abbruzzese
Nov 23, 2012 07:55 PM|LINK
I have a a [Range( 0.0001, 0.9000 ) DataAnnotations on one of my Entity classes that fails with I enter a legal value of 0.010 and 0.0150 into the text field.
1) Why is this happening? and
2) What can be done to correct this issue?
Nov 23, 2012 10:01 PM|LINK
0.0001f is the right way to write a float....try this way
Nov 24, 2012 12:19 AM|LINK
Okay, I put your suggestion into the project (in 4 places since I have two fileds that use the [Range(...)[ DataAnnnotation.
Of course it still fails to validate with values of 0.010 and 0.0150.
Part of the problem may be the when the form is displayed those to fields have a value of 0.00...
Nov 24, 2012 08:56 AM|LINK
If this is happening, the only other explanation is a culture problem. That is, the browser client culture is set to a culture where integer and decimals are spearated by comma instead of period, so the data annotation interpret , in the usual way, since
it is part of the program that AWAYS use . as a decimal separator, while the browser not. As a first experiment try substituting . with , in your textbox (not in the data annotation).
You may solve by using a globalization library if the failure is with client side validation read this post of my blog:
Nov 24, 2012 02:31 PM|LINK
The culture for the site is already set to:
not that correct???
Nov 24, 2012 02:58 PM|LINK
It appars correct...but is your errors signalled on the client side by unobtrusive validation or in the server side?
Nov 24, 2012 03:03 PM|LINK
It could be, but only if the unobtrusive validation is getting the Error Meesages from the Server side somehow.
Nov 24, 2012 03:05 PM|LINK
error messages ARE ALWAYS taken from the server, also errors shown by unobtrusive validation....bu anyway just verify if form submit or not...if it is not ablr to submit the error take place on the client side.
Nov 24, 2012 03:26 PM|LINK
It seems to be from the server side.
These are the scripts that are running on the site:
If I comment out the MofrlState.IsValid() if statement I get the values but an error occures when I attempt to add
the Entity to the database.
Nov 24, 2012 03:32 PM|LINK
you forgot to include the