[英]Displaying decimal values retrieved from Sql Server Database with thousands seperator on an Asp.net/Mvc Razor view
I am working on an ASP.NET/MVC application and I fall into this issue. 我正在使用ASP.NET/MVC应用程序,因此遇到了这个问题。 I am using decimal data type to store my data in the Microsoft SQL Server Database, say fieldname is
Volume
. 我正在使用十进制数据类型将数据存储在Microsoft SQL Server数据库中,比如说fieldname是
Volume
。
I want to retrieve this in Razor view say using @model.Volume
. 我想使用
@model.Volume
在Razor视图中检索此@model.Volume
。 It is displaying quite alright however I want to display data in this format 1,000000.00
, 1,000.00
not the normal 1000000
. 它显示的是相当好的,但是我想在这个格式来显示数据
1,000000.00
, 1,000.00
不能正常1000000
。
Model Class: 型号类别:
public class Quantity {
public decimal Volume { get; set; }
}
View: 视图:
@model.Volume
In your model add the following data annotation to provide metadata to your view. 在模型中添加以下数据注释,以向视图提供元数据。 This helps keep the logic for your model centralised.
这有助于使模型的逻辑保持集中。
[DisplayFormat(DataFormatString = "{0:n}")]
public decimal Volume { get; set; }
您可以在视图中使用ToString()格式设置功能:
@Model.Volume.ToString("#,##0.00")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.