Try testing the
OperatorNotes
property for
null
before trying to access one of its properties:
@if (Model.OperatorNotes != null && Model.OperatorNotes.ApprovedBy.HasValue)
Alternatively, if you're using C# 6, you could use
the Null-conditional operator[
^]:
@if (Model.OperatorNotes?.ApprovedBy.HasValue)
(Note the extra
?
in the property access:
OperatorNotes?.ApprovedBy
)