在剃刀之差()(括号)和{}(大括号) [英] Difference between ( ) (parenthesis) and { } (curly brackets) in Razor

查看:153
本文介绍了在剃刀之差()(括号)和{}(大括号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么它们两者之间的差异。我以为他们是相同的,但今天我意识到,他们都没有。

为什么这是正确的。

  @(Model.WillAttend ==真的吗?
    这将是一个令人兴奋的派对与你:
    很抱歉,你会失去beeer)

这是不是:

  @ {Model.WillAttend ==真的吗?
    这将是一个令人兴奋的派对与你:
    很抱歉,你会失去beeer}


解决方案

在括号只是一个明确的前pression,你会发现,你并不需要一个分号。该支架是code座,中使用,就像任何其他棋子code的。防爆pressions他们已经提交输出作为HTML的一部分,而code块没有。

菲尔哈克居然写了好的底漆上的一些语法剃刀

What is the difference between them both. I thought they were the same but today I realized that they are not.

Why this is correct

@(Model.WillAttend == true ? 
    "This will be an exciting party with you" : 
    "So sorry. You'll lose the beeer")

and this is not:

@{Model.WillAttend == true ? 
    "This will be an exciting party with you" : 
    "So sorry. You'll lose the beeer"}

解决方案

The paren is just an explicit expression, and you will notice that you do not need a semi-colon. The brackets are a code block, to be used just like any other piece of code. Expressions have their output submitted as part of the HTML, whereas code blocks do not.

Phil Haack actually wrote a good primer on some Razor syntax

这篇关于在剃刀之差()(括号)和{}(大括号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆