@:在ASP.net MVC Razor中是什么意思? [英] What does @: mean in ASP.net MVC Razor?
问题描述
我正在使用别人编写的ASP.net MVC Razor视图.我看到它包含以下内容:
I'm working on an ASP.net MVC Razor view that someone else wrote. I see that it contains the following:
<span>
@:
</span>
我知道@
符号允许我在视图中插入代码,但是@:
代表什么?
I know that the @
symbol allows me to insert code into a view, but what does @:
stand for?
推荐答案
在MVC中,@
是各自的字符,可让您在HTML(在.cshtml内)内使用剃刀,在运行时(或预编译)将使用剃刀.转换为c#.
In MVC, @
is the respective char that allows you to use razor inside HTML (inside a .cshtml) which in runtime (or precompiled) will be converted to c#.
使用@
,您可以在HTML中编写C#;使用@:
,您可以在C#中编写HTML.
With @
you may write C# within HTML and with @:
you may write HTML within C#.
示例:
@foreach (TestClass item in Model)
{
@:@item.Code - @item.Name
}
如果没有@:
,将无法执行此操作,因为第一个@
之后的所有字符都将被视为C#.
Without the @:
it wouldn't be possible to do this, since all the chars after the first @
will be considered as C#.
这样,您说的是从item
获取两个变量,并将char -
放在它们之间,结果是一个内容块(或html/text)
This way you are saying that you are getting the two variables from item
and placing the char -
between them and the result is a content block (or html/text)
这篇关于@:在ASP.net MVC Razor中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!