string.Format Return value of pure method is not used

六月ゝ 毕业季﹏ 提交于 2019-12-12 02:45:51

问题


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!


回答1:


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:


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>


来源:https://stackoverflow.com/questions/32957318/string-format-return-value-of-pure-method-is-not-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!