C# ASP.NET MVC – New Null-Conditional Operator in Razor

asp.net-mvcc#-6.0c++razor

So since C# 6.0 came out, I've been using the null-conditional operator quite a lot. Example:

Model?.Person?.Zip

However, I now have a situation where I have a solution where the customer operates on domain models in the view. While I would hunt down the developer with an axe, I find it easier to just do some null checks in the view.

However, when I go this in Razor:

@Model?.Person?.Zip

My Model? is seen as dynamic, but ? breaks the dynamic things and rest is rendered as text.

How do you solve this?

Best Answer

Just a guess

@(Model?.Person?.Zip)
Related Question