2017-03-17 73 views
0

我需要打印下我的問題if語句總是打印文本

所有的代碼,如果在@store.GuaranteePolicy打印所有<tr>數據。如果沒有數據,則不會打印任何內容。

無論@store.GuaranteePolicy中是否有數據,「付款」總是打印,但爲什麼?

我說,如果(store.GuaranteePolicy比空不同,則打印)

if語句正在與此:

  • 如果在store.GuaranteePolicy一切數據打印完美
  • 如果在store.GuaranteePolicy沒有數據的文本沒有打印,付款方式:打印。所以即使它不是真的,整個<tr>也會被打印出來?

    @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> 
    } 
    
+1

你有debuged您的應用程序和看看store.GuaranteePolicy的價值是什麼,當你認爲它不應該是公關inted? –

+0

我不知道它是什麼,但有沒有一個零項目列表或類似的東西?默認值? – TheLethalCoder

+0

也許嘗試使用Count()方法,如果它是一個集合並且與0 – daniell89

回答

2

如果GuaranteePolicy是一家集試試這個:

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

} 

如果字符串:

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

} 

等等...

+0

完美的作品,謝謝你的:-) – M375