Html.DisplayFor十进制格式? [英] Html.DisplayFor decimal format?

查看:498
本文介绍了Html.DisplayFor十进制格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个十进制值,例如: 59625879,00

I have a decimal value for example: 59625879,00

我要显示这样这个值: 59.625,879 59625,879

I want to show this value like this: 59.625,879 or 59625,879

我怎样才能做到这一点与 @ Html.DisplayFor(X => x.TAll,的String.Format())

How can I do this with @Html.DisplayFor(x => x.TAll, String.Format()) ?

感谢。

推荐答案

[DisplayFormat] 属性装饰您的视图模型属性并指定所需的格式为:

Decorate your view model property with the [DisplayFormat] attribute and specify the desired format:

[DisplayFormat(DataFormatString = "{0:N}", ApplyFormatInEditMode = true)]
public decimal TAll { get; set; }

,然后在您的视图:

and then in your view:

@Html.DisplayFor(x => x.TAll)


如果你不想做这个视图模型,你也可以做到这一点的看法里面另一种可能性:


Another possibility if you don't want to do this on the view model you could also do it inside the view:

@Model.tAll.ToString("N")

但我会建议你第一种方法。

but I would recommend you the first approach.

另一种可能性是写小数点类型的定制显示模板(〜/查看/共享/ DisplayTemplates / MyDecimalTemplate.cshtml

Yet another possibility is to write a custom display template for the decimal type (~/Views/Shared/DisplayTemplates/MyDecimalTemplate.cshtml):

@string.Format("{0:N}", Model)

和则:

@Html.DisplayFor(x => x.TAll, "MyDecimalTemplate")

这篇关于Html.DisplayFor十进制格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆