6
可能重複:
How to use ternary operator in razor (specifically on HTML attributes)?三元運算符在Razor視圖
我嘗試做以下,但它的示數,所以我明明做錯事剃刀語法:
<td>@{item.Licence.MachineId != null ? @:"TB Master" : @:"HandHeld"} </td>
可能重複:
How to use ternary operator in razor (specifically on HTML attributes)?三元運算符在Razor視圖
我嘗試做以下,但它的示數,所以我明明做錯事剃刀語法:
<td>@{item.Licence.MachineId != null ? @:"TB Master" : @:"HandHeld"} </td>
以下應該工作:
<td>@(item.Licence.MachineId != null ? "TB Master" : "HandHeld")</td>
試試這個
<td>@(item.Licence.MachineId != null ? "TB Master" : "HandHeld")</td>
相關:http://stackoverflow.com/questions/7729024/asp-net-mvc-razor-ternary – 2015-11-19 14:01:51