Ternary operator in razor view

Possible duplicate:
How to use the ternary operator in a razor (in particular, for HTML attributes)?

I am trying to do the following, but its an error, so I am obviously doing something wrong with Razor syntax:

<td>@{item.Licence.MachineId != null ? @:"TB Master" : @:"HandHeld"} </td> 
+6
source share
2 answers

The following should work:

 <td>@(item.Licence.MachineId != null ? "TB Master" : "HandHeld")</td> 
+17
source

try it

 <td>@(item.Licence.MachineId != null ? "TB Master" : "HandHeld")</td> 
+1
source

Source: https://habr.com/ru/post/890073/


All Articles