MVC3数据注释Dataformat问题

时间:2014-04-21 18:09:12

标签: asp.net-mvc-3 data-annotations dataformat

我有一个MVC2 C#.Net网络应用程序。我们希望我们的一个属性始终显示两位小数:即

.1 display as 0.10
1 display as 1.00
1.1 display as 1.10
1.21 display as 1.21

我已应用以下数据注释

[Display(Name = "Complexity/Scaling Factor")]
[DefaultValue(1.00)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0.00}")]
[Required(ErrorMessage = "Please enter a numeric value with up to two decimal places greater than zero.")]
[RegularExpression(@"^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$", 
    ErrorMessage = "Please enter a numeric value with up to two decimal places greater than zero.")]
public virtual double ComplexityFactor { get; set; }

...但是生成的属性无法正确显示。

2.1 displays as 2.1
1 displays as 1

想法?

0 个答案:

没有答案