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.
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:
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.
eric2820
Contributor
2777 Points
1161 Posts
[Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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.
Two Qustions:
1) Why is this happening? and
2) What can be done to correct this issue?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
Nov 23, 2012 10:01 PM|LINK
0.0001f is the right way to write a float....try this way
Mvc Controls Toolkit | Data Moving Plug-in Videos
eric2820
Contributor
2777 Points
1161 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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...
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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:
Globalization, Validation and Date/Number Formats in Asp.Net MVC
Mvc Controls Toolkit | Data Moving Plug-in Videos
eric2820
Contributor
2777 Points
1161 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
Nov 24, 2012 02:31 PM|LINK
The culture for the site is already set to:
<globalization uiCulture="en" culture="es-US" />
Is not that correct???
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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?
Mvc Controls Toolkit | Data Moving Plug-in Videos
eric2820
Contributor
2777 Points
1161 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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.
Mvc Controls Toolkit | Data Moving Plug-in Videos
eric2820
Contributor
2777 Points
1161 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
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:
<link href="/Content/BackOffice.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-validate.min.js" type="text/javascript"></script>
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.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: [Range( 0.0001, 0.9000] DataAnnotation fails with 0.010 and 0.015!
Nov 24, 2012 03:32 PM|LINK
you forgot to include the
jquery.validate.unobtrusive.min.jsfile after/jquery-validate.min.jsMvc Controls Toolkit | Data Moving Plug-in Videos