【问题标题】:How to format Decimal in Asp.Net Mvc3如何在 Asp.Net Mvc3 中格式化十进制
【发布时间】:2012-09-27 07:36:53
【问题描述】:

我需要验证我的编辑器字段才能输入产品价格,比如他可以输入整数为 100,或者小数点后只允许两位数为 85.12,如果用户输入 85,12 也是有效的,它存储在数据库中如 85.12。 模型类:

[Required]

[LocalizedDisplayName("PRICE_PER_COLLI", NameResourceType = typeof(Strings))] [DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]

public decimal ColliPrice { get; set; }

查看:

<%: Html.EditorFor(model => model.ColliPrice) %> 
<%: Html.ValidationMessageFor(model => model.ColliPrice)  

【问题讨论】:

  • &lt;%: 不是 MVC 3 格式吗?你不是说MVC2吗??

标签: asp.net asp.net-mvc-3


【解决方案1】:

我以前做过这样的事情:

@Html.TextBox("ColliPrice", Model.ColliPrice.ToString("0.00")) 
@Html.ValidationMessageFor(model => model.ColliPrice)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    相关资源
    最近更新 更多