if语句在true时失败

时间:2017-02-15 20:34:37

标签: c# .net asp.net-mvc razor casting

当我构建项目时,这段代码失败了。如果声明必须检查ParkingLot是否为真。我认为这样做的方法是以下代码:

    <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:不能   隐式转换类型''Newtonsoft.Json.Linq.JValue''到''bool''。   存在显式转换(您是否错过了演员?)

有人能看到我在这里做错了吗?

1 个答案:

答案 0 :(得分: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>
相关问题