I have a model property that I'm trying to execute using the EditorFor template, and I'm trying to apply formatting using the DisplayFormat attribute. However, it does not work at all - it is completely ignored.
Here is my template:
@model System.Decimal? @Html.TextBoxFor(m => m)
Here is my model:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0.00}")] public decimal? Retail { get; set; }
Here is my view:
@Html.EditorFor(m => m.Retail)
But it creates a text box with the following value:
189.9900
It seems pretty straight forward, but it doesn't work, and I have no idea why.
UPDATE: Just for beats, I tried it with the DisplayFor template and it worked:
@Html.DisplayFor(m => m.Retail)
So why did the DisplayFor pattern work, but not the EditorFor pattern, when did I set ApplyFormatInEditMode to true?
UPDATE 2: It doesn't matter, the reason is that my decimal display pattern was hard-coded that way. Therefore, my display template also does not work.
decimal asp.net-mvc asp.net-mvc-3 mvc-editor-templates
Jerad rose
source share