【问题标题】:Show SQL decimal type without decimal if there are no decimals如果没有小数,则显示不带小数的 SQL 小数类型
【发布时间】:2018-10-04 09:56:45
【问题描述】:

我正在使用 ASP.NET Core v2,

见图片显示SQL数据类型和模型中的代码

如果没有小数,我不想显示小数

以下html用于显示网页上的输入

<input tabindex=@ordTab asp-for="@Model.OrderLineList[i].NoInvoAb" />

下面是SQL

下面是模型

我尝试了许多不同的显示格式/数据格式字符串,但我使用什么似乎并不重要,就像格式似乎根本不适用

[Required]
[DisplayFormat(DataFormatString = "{0:0}")]
[Display(Name = "Ordered")]
public decimal NoInvoAb { get; set; }

这是我的结果是错误的,如果值为 2,它应该显示 2 而不是 2,00

我做错了什么

【问题讨论】:

标签: model-view-controller asp.net-core decimal format-string


【解决方案1】:

DisplayFormat 默认用于显示。在这里,看起来值在输入中。如果您希望格式也适用于那里,那么您需要将ApplyFormatInEditMore = true 添加到您的DisplayFormat 属性中。

[Required]
[DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
[Display(Name = "Ordered")]
public decimal NoInvoAb { get; set; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-31
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多