在MVC Razor中创建IF - Else语句

时间:2016-11-07 07:50:30

标签: asp.net-mvc asp.net-mvc-3 if-statement razor

我在运行MVC Html Razor时收到错误Object reference not set to an instance of an object.。我在google上搜索如何在剃须刀中创建IF-Else并找到一些好的答案。但就我而言,我收到了一个错误。

我的代码

<td  style="text-align: left" >
                    <div id="divEBSN">
                    @if (Model.RCEducationalBackground.School.SchooldName != null)
                    {
                       <span style="color: Red">@Html.DisplayFor(model => model.RCEducationalBackground.School.SchooldName)</span>    
                    }
                    else { 
                        <span style ="color:Red">@Html.DisplayFor(model => model.RCEducationalBackground.SchoolNameEducBG)</span>
                    }
                    </div>
                </td>

0 个答案:

没有答案