Here is the code that is causing the problem, it is inside the view:
@{
if(item.Contract_Type != null)
{
dangerhtml = (item.Contract_Type == "Premium") ? "class=\"warning\"" : "";
}
}
<td @dangerhtml>
@Html.DisplayFor(modelItem => item.Contract_Type)
</td>
This code is sitting inside a foreach:
@foreach (var item in Model) {
..etc
}
It is throwing a NullReferenceException on the if line. The code works fine if I remove all the above and just do:
<td>
@Html.DisplayFor(modelItem => item.Contract_Type)
</td>
But I am looking to set the class for the cell based on the contents of the item.Contract_Type
Any help appreciated!