2017-02-15 91 views
1

這段代碼在構建我的項目時失敗。如果聲明必須檢查ParkingLot是否爲真。我認爲這樣做是下面的代碼的方式:if語句失敗時爲true

<th class="small-12 large-6 columns last"> 
     <table> 
      <tr> 
       <th width="300"> 
        <p class="text-left small-text-left"> 
         @if(Model.Point.Store.JsonDynamic.En.Motel.ParkingLot == True) 
         { 
          <span>Possibility for parking</span><br> 
         } 
        </p> 
       </th> 
       <th class="expander"></th> 
      </tr> 
     </table> 
    </th> 

但我得到這個錯誤:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type ''Newtonsoft.Json.Linq.JValue'' to ''bool''. An explicit conversion exists (are you missing a cast?)

任何人都可以看到我在做什麼錯在這裏?

+1

嘗試鑄造爲布爾。 @if((bool)Model.Point.Store.JsonDynamic.En.Motel.ParkingLot == True){...} – Aaron

回答

2

試試這個

<th class="small-12 large-6 columns last"> 
     <table> 
      <tr> 
       <th width="300"> 
        <p class="text-left small-text-left"> 
         @(if((bool)Model.Point.Store.JsonDynamic.En.Motel.ParkingLot == True){<span>Possibility for parking</span><br>}) 
        </p> 
       </th> 
       <th class="expander"></th> 
      </tr> 
     </table> 
    </th> 
+0

是的,演員應該修復它。 –

+0

你好。謝謝你的答案。這聽起來像一個解決方案。當我嘗試運行代碼時,出現以下錯誤:RazorEngine.Templating.TenokateCompilationException:編譯模板時出現錯誤。請嘗試以下方法來解決問題:如果問題是關於丟失/無效引用或多重定義,請嘗試手動加載缺失的引用。 – Mimi

+0

看起來像這個錯誤是沒有關係的。你可以在關閉Visual Studio後再試一次,然後加載所有的引用? –