【发布时间】:2013-09-22 15:19:30
【问题描述】:
我的虚拟机中有一个小数属性:
[Required, Display(Name = "Manual Payment Amount")]
[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
public decimal EnteredPaymentAmount { get; set; }
视图如下所示:
@Html.TextBoxFor(m => m.EnteredPaymentAmount, new { style = "width:200px", maxlength = Model.MaximumPaymentAmount.ToString("N").Length })
我想限制输入只有 2 位小数
这样做的最佳方法是什么?我尝试应用 DisplayFormat 以及 TextBoxFor 上的格式,但这仍然通过了验证,这意味着我可以输入 3 个小数位。
【问题讨论】:
标签: asp.net-mvc