0
非常沮喪!EditorFor ApplyFormatInEditMode貨幣不工作編輯
在初始顯示中,貨幣顯示正常,但是當我編輯該值時,它不是格式。我設置了一個新的項目來說明。
public class TestViewModel
{
[DisplayName("Text Box For")]
public decimal Cost1 { get; set; }
[DisplayName("Editor For")]
[DisplayFormat(DataFormatString = "{0:C}", ApplyFormatInEditMode = true)]
public decimal Cost2 { get; set; }
}
@model EditorForTest.Models.TestViewModel
<br/>
@Html.LabelFor(m => m.Cost1)
@Html.TextBoxFor(m => m.Cost1, new { Value = String.Format("{0:C}", Model.Cost1) })
<br/>
@Html.LabelFor(m => m.Cost2)
@Html.EditorFor(m => m.Cost2)
<br/>
public ActionResult Test()
{
return View(CurrentTest);
}
private static TestViewModel _currentTest;
private static TestViewModel CurrentTest
{
get { return _currentTest ?? (_currentTest = GetNewTest()); }
set { _currentTest = value; }
}
public static TestViewModel GetNewTest()
{
TestViewModel testViewModel = new TestViewModel();
testViewModel.Cost1 = 1234;
testViewModel.Cost2 = 1234;
return testViewModel;
}
它看起來不錯,打開時:
但是當你編輯,格式丟失。
什麼我做錯了?????