I\'m running MVC3 with Razor and noticed that decimal values are truncated to 2 decimal places when in edit mode. I\'ve managed to get round it by annotating my property wit
That's how the default Decimal editor template is defined:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.TextBox("", ModelValue, new { @class = "text-box single-line" }) %>
Notice the {0:0.00}
format.
So you have two possibilities:
double
instead of decimal
as type in your modelModify the default editor template by creating a custom ~/Views/Shared/EditorTemplates/Decimal.cshtml
which might simply look like this:
@Html.TextBox(
"",
ViewData.TemplateInfo.FormattedModelValue,
new { @class = "text-box single-line" }
)
You probably might want to modify the display template as well.