2

I've tried one or two combinations of using the null propagation operator in an ASP.NET MVC 5.2.3 razor view but the compiler doesn't understand this syntax at all.

<input type="text" 
       name="Name" 
       class="form-control" 
       placeholder = "John Doe" 
       value = "@(Model?.Name)" />

Short of this, I will have to either use a ternary operator or wrap the whole thing in a large if (Model == null) statement with an else block. How do I avoid that?

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336

0 Answers0