0
我有一個MVC應用程序,它允許ADM用戶動態更改小數位的小數位數。 我需要改變顯示格式,所以我寫了下面的代碼:DecimalDynamicDisplayFormat常量表達式錯誤
public ForecastProfitView(decimal? literPerUnit = null, int? _decimalPlaces = null)
{
LiterPerUnit = ((literPerUnit ?? 0) == 0) ? 1 : literPerUnit.Value;
decimalPlaces = ((_decimalPlaces ?? 0) == 0) ? 2 : _decimalPlaces.Value;
}
private decimal LiterPerUnit { get; }
private static int decimalPlaces { get; set; }
[Display(ResourceType = typeof(Language.App_GlobalResources.AnalysisAndManagement), Name = "BottlingMaterialsCost")]
[DecimalDynamicDisplayFormat(decimalPlaces)]
public decimal BottlingMaterialsCost { get; set; }
當我設置[DecimalDynamicDisplayFormat(decimalPlaces)]
,它給了我一個錯誤,因爲我需要一個常量表達式。有沒有辦法解決這個問題?
無法弄清楚 – Reznor13
我更新了我的答案基於你的'decimalPlaces'財產。主要想法是以某種方式計算該格式。 –
它的工作,非常感謝! – Reznor13