I am using razor to display decimals from my view model and then trying to format the decimals into currency:
我正在使用剃刀从我的视图模型中显示小数,然后尝试将小数格式化为货币:
@if (Model != null && Model.Order != null)
{
foreach (var item in Model.Order.Where(x => x.OrderInStep2 != null))
{
String.Format("{0:C}", item.OrderInStep2)
}
}
I am getting an Return value of pure method is not used
warning, but I thought it should still work. However, the formatted item is not displaying at all. It does display when I take away the formatting though. Am I missing something here? Thanks!
我得到的纯值方法的返回值没有使用警告,但我认为它应该仍然有用。但是,格式化的项目根本不显示。当我拿走格式时它会显示。我在这里错过了什么吗?谢谢!
2 个解决方案
#1
0
You need to render the value in a code block like this:
您需要在代码块中呈现值,如下所示:
@if (Model != null && Model.Order != null)
{
foreach (var item in Model.Order.Where(x => x.OrderInStep2 != null))
{
<text>@String.Format("{0:C}", item.OrderInStep2)</text>
}
}
#2
0
You just run the code, and do nothing with the result.
您只需运行代码,并对结果不执行任何操作。
Put the result within text tag:
将结果放在文本标记中:
<text>String.Format("{0:C}", item.OrderInStep2)</text>
#1
0
You need to render the value in a code block like this:
您需要在代码块中呈现值,如下所示:
@if (Model != null && Model.Order != null)
{
foreach (var item in Model.Order.Where(x => x.OrderInStep2 != null))
{
<text>@String.Format("{0:C}", item.OrderInStep2)</text>
}
}
#2
0
You just run the code, and do nothing with the result.
您只需运行代码,并对结果不执行任何操作。
Put the result within text tag:
将结果放在文本标记中:
<text>String.Format("{0:C}", item.OrderInStep2)</text>