gpt4 book ai didi

asp.net-mvc - Html.DisplayFor十进制格式?

转载 作者:行者123 更新时间:2023-12-03 10:46:19 25 4
gpt4 key购买 nike

我有一个十进制值,例如:59625879,00
我想像这样显示这个值:59.625,87959625,879
我怎么能用 @Html.DisplayFor(x => x.TAll, String.Format()) 做到这一点?

谢谢。

最佳答案

[DisplayFormat] 装饰你的 View 模型属性属性并指定所需的格式:

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

然后在您看来:
@Html.DisplayFor(x => x.TAll)

另一种可能性,如果您不想在 View 模型上执行此操作,您也可以在 View 内执行此操作:
@Model.tAll.ToString("N")

但我会推荐你​​第一种方法。

另一种可能性是为十进制类型( ~/Views/Shared/DisplayTemplates/MyDecimalTemplate.cshtml )编写自定义显示模板:
@string.Format("{0:N}", Model)

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

关于asp.net-mvc - Html.DisplayFor十进制格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com