使用DisplayNameFor时格式化货币

时间:2015-06-01 20:39:06

标签: c# asp.net-mvc

如何将显示从50000更改为500.00?

<div class="display-label">
         @Html.DisplayNameFor(model => model.Price)
</div>

这很有效,但很难看。

$@((Model.Price / 100)).00

输入: 50000 输出: $ 500.00

它必须是一种更清洁的方式来做到这一点。

也尝试了这个但是我收到了错误。

@((Model.Price / 100).ToString("c"))

感谢您的阅读。

1 个答案:

答案 0 :(得分:0)

在你的模型中应用它

      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]
      public decimal Price { get; set; }
相关问题