我有一个数字字段,定义为小数。我试图将其显示为整数值。
我的模特:
[Column(CanBeNull = true, DbType = "numeric", Name = "VHCL_ODOMTR")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:f0}", HtmlEncode = false, NullDisplayText = "")]
[Display(Name = "Odometer")]
public decimal? VehicleOdometer { get; set; }
我的剃刀:
@Html.TextBoxFor(model => model.VehicleOdometer)
我的输出始终是一个带有一个十进制小数的文本框。我不能停止这样做。我尝试了{0:D},{0:#},并使用大写字母F而不是小写字母。即使尝试使用“ F9”,它也会显示1个小数而不是9个。似乎完全忽略了DataFormatProperty。
这是因为DisplayFormatAttribute设计为与模板化视图帮助器(即Html.EditorFor
和Html.DisplayFor
)一起使用。因此,为了使其正常工作,您需要使用:
@Html.EditorFor(model => model.VehicleOdometer)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句