十进制领域和本地化MVC3编辑 [英] MVC3 edit for decimal fields and localization
问题描述
我的语言环境使用逗号,
,而不是一个点。
的小数点分隔符。
My locale uses a comma ,
, and not a dot .
for decimal separator.
在MVC3,当我打开其中的十进制值显示与编辑观点
In MVC3, when I open an Edit view where the decimal values are shown with
@Html.EditorFor(model => model.MyDecimalVal)
值被正确地显示。
the value is shown correctly.
当我用逗号输入值,我得到错误值不是一个数字,如果我进入点值,我没有得到任何错误,但实际上没有价值被保存。
When I enter value with comma, I get error "Value is not a number" and if I enter value with dot, I get no error, but actually no value is saved.
如何处理这种情况?
推荐答案
四处逛逛这个通过调整您的验证逻辑已经被解释所以这里是一个不同的方法。
Getting around with this by tweaking your validation logic has been already explained so here is a different approach.
把低于code你的web.config文件中在<&的System.Web GT;
节点,如果你想培养设置为连接
。这将需要小数分隔符的护理:
Put the below code inside your web.config file under the <system.web>
node if you would like to set the culture to en
. It will take care of decimal delimiter:
<globalization culture="en-US" uiCulture="en" />
我不知道,但对的DateTime
,你仍然绑定到您的服务器的语言环境。
I am not sure but for DateTime
, you are still bound to your server's locale.
这篇关于十进制领域和本地化MVC3编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!