[英]Value of decimal number in MVC TextBoxFor is expanded by decimal places
當打開一個包含小數位數字(在這種情況下設置為 4)的(剃刀)頁面時,逗號分隔符被解釋為千位分隔符,它通過小數位擴展數字,如下圖所示:
這發生在 NopCommerce 3.8 開發樹的管理面板中,並且僅發生在遠程服務器上。 我在本地的調試版本中沒有看到這個問題,所以這可能與服務器設置甚至底層數據庫(Microsoft SQL-Server)有關。 我不確定這是一個 NopCommerce 問題,所以我不把它限制在那個標簽上。
我知道由於 Kendo Grid 的工作方式,NopCommerce 正在強制管理面板中的文化。 同樣,我不確定這與實際問題有什么關系。
這個問題也體現在文本框不允許使用“,”字符這一事實中。 我只能使用'.'。 嘗試保存像“0.20”這樣的數字被終止,消息如下:
值“0.2000”對...無效
更新 1(在 Global.asax.cs 中設置的文化):
if (webHelper.GetThisPageUrl(false).StartsWith(string.Format("{0}admin", webHelper.GetStoreLocation()),
StringComparison.InvariantCultureIgnoreCase))
{
//admin area
//always set culture to 'en-US'
//we set culture of admin area to 'en-US' because current implementation of Telerik grid
//doesn't work well in other cultures
//e.g., editing decimal value in russian culture
CommonHelper.SetTelerikCulture();
}
else
{
//public store
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var culture = new CultureInfo(workContext.WorkingLanguage.LanguageCulture);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
這似乎是它使用的文化的問題。 嘗試在 web.config 中指定要使用的文化:
<configuration>
<system.web>
<globalization uiCulture="en" culture="en-US" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.