0
我有一個預先填充的金額字段。當我運行網絡應用程序時,它顯示爲125.4500。我試圖格式化,但我沒有運氣。將文本框從十進制格式設置爲美元金額
這裏是我的PaymentModel:
[Required]
[DataType(DataType.Currency)]
[DisplayFormat(DataFormatString = "{0:F2}", ApplyFormatInEditMode = true)]
[Display(Name = "Payment Amount")]
public decimal Amount { get; set; }
的DataFormatString
似乎沒有任何影響。
而且我在表格上的代碼:
@Html.TextBoxFor(m => m.Amount, new { @class = "makePaymentTextRight width90" })
我嘗試這樣做:
@Html.TextBoxFor(m => string.Format("{0:F2}",m.Amount), new { @class = "makePaymentTextRight width90" })
但是,這給了我這個錯誤:
System.InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
我如何得到這個格式到2位小數?
時才尊重@ StephenMuecke Wow,很簡單。發佈作爲答案,我會給你信用。 Tyvm! – ErocM