string.Format Return value of pure method is not u

2019-09-12 17:55发布

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条回答
【Aperson】
2楼-- · 2019-09-12 18:00

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>
查看更多
何必那么认真
3楼-- · 2019-09-12 18:12

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>
    }
}
查看更多
登录 后发表回答