I'm running across lots of cases where I want to display something along the lines of
@ev.Event.Instructor.Name
But the instructor property is allowed to be null. In those cases the "Object reference not set to an instance of an object." error is thrown but I'd like to ignore that and have nothing returned..
Is there a better way to handle this than to create lots of ternary expressions all over the place to check for null?
The equivalent php expression would be
@$ev.Event.Instructor.Name
I've been translating some webforms views to MVC and the equivalent Eval statement would ignore null reference errors.
To clarify: The @ev property is coming from a linq query and there are also cases where I have
@ev.mainContact.FirstName @ev.mainContact.LastName
@ev.mainContact.Company.Name
Where not only the mainContact can be null but the mainContact's company can also be null. It seems like an equally bad solution to select every single attribute with a ternary checking for null.