C# if语句始终打印文本

C# if语句始终打印文本,c#,razor,C#,Razor,我需要打印我问题下的所有代码 如果@store.guarantePolicy中有数据,请打印所有。如果没有数据,则不打印任何内容 无论@store.guarantePolicy中是否有数据,那么“付款”总是printet,但为什么 我说过如果(store.guarantePolicy不同于null,则打印) if语句正在处理以下内容: 如果存储中有数据。保证策略所有内容都打印完美 如果store.guarantePolicy中没有数据,则不会打印文本,但会打印单词Payment:。所以即使不是

我需要打印我问题下的所有代码

如果
@store.guarantePolicy中有数据,请打印所有
。如果没有数据,则不打印任何内容

无论
@store.guarantePolicy
中是否有数据,那么“付款”总是printet,但为什么

我说过如果(store.guarantePolicy不同于null,则打印)

if语句正在处理以下内容:

  • 如果
    存储中有数据。保证策略
    所有内容都打印完美
  • 如果
    store.guarantePolicy
    中没有数据,则不会打印文本,但会打印单词Payment:。所以即使不是真的,整个
    也会被打印出来

    @if (store.GuaranteePolicy != null) { 
    <tr>
        <th class="small-12 large-6 columns first">
            <table>
                <tr>
                    <th width="300">
                        <p class="text-left small-text-left"><strong>Payment:</strong></p>
                    </th>
                </tr>
            </table>
        </th>
        <th class="small-12 large-6 columns last">
            <table>
                <tr>
                    <th width="300">
                        <p class="text-left small-text-left">
                            <span>@store.GuaranteePolicy</span>
                        </p>
                    </th>
                    <th class="expander"></th>
                </tr>
            </table>
        </th>
    </tr>
    }
    
    @if(store.guarantePolicy!=null){
    

    付款:

    @仓储保障政策

    }

如果GuarantePolicy是一个集合,请尝试以下操作:

@if(store.GuaranteePolicy != null && store.GuaranteePolicy.Count > 0)
{

}
如果字符串:

@if(!string.IsNullOrWhiteSpace(store.GuaranteePolicy))
{

}

依此类推……

如果GuarantePolicy是一个集合,请尝试以下操作:

@if(store.GuaranteePolicy != null && store.GuaranteePolicy.Count > 0)
{

}
如果字符串:

@if(!string.IsNullOrWhiteSpace(store.GuaranteePolicy))
{

}

诸如此类……

您是否调试了应用程序,并查看了store.GuarantePolicy在您认为不应打印时的价值?我不知道它是什么,但是否有零项列表或类似的内容?默认值?如果它是一个集合,可以尝试使用Count()方法,并与0比较,保证策略是否可以为“空”而不是null?试一试你是否调试了你的应用程序,并查看了store.GuarantePolicy在你认为不应该打印时的价值?我不知道它是什么,但是否有零项列表或类似的内容?默认值?如果它是一个集合,可以尝试使用Count()方法,并与0比较,保证策略是否可以为“空”而不是null?尝试