纯法的String.Format返回值不使用 [英] string.Format Return value of pure method is not used

查看:171
本文介绍了纯法的String.Format返回值不使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的剃刀,以显示我的视图模型小数,然后试图向小数格式化为货币:

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!

推荐答案

您需要渲染在这样的code座的值:

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>
    }
}

这篇关于纯法的String.Format返回值不使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆