非常沮丧!!!!
在初始显示上,货币显示正常,但是当我编辑值时,它没有格式化。我设置了一个新项目来说明。
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;
}
打开后看起来没问题:
但是当你编辑它时,格式会丢失。
我究竟做错了什么?????