Ric*_*olo 23 asp.net-mvc razor asp.net-mvc-3
它们之间有什么区别.我以为他们是一样的,但今天我意识到他们不是.
为什么这是正确的
@(Model.WillAttend == true ?
"This will be an exciting party with you" :
"So sorry. You'll lose the beeer")
Run Code Online (Sandbox Code Playgroud)
这不是:
@{Model.WillAttend == true ?
"This will be an exciting party with you" :
"So sorry. You'll lose the beeer"}
Run Code Online (Sandbox Code Playgroud)
对于问题:“为什么第二个无效?”,除了 Betty 和 Justin 所说的,还有您所展示内容的特定问题:在大括号内,您需要您的代码遵循 c# 的正常语法,因此您可以不只是一个松散的“a==b?c:d”,而不将结果分配给某些东西。你需要一个分号。所以你可以说
@{string message = Model.WillAttend == true ?
"This will be an exciting party with you" :
"So sorry. You'll lose the beeer";}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7868 次 |
| 最近记录: |