2017-02-15 212 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后再试一次,然后加载所有的引用? –