@: 在 ASP.net MVC Razor 中是什么意思? [英] What does @: mean in ASP.net MVC Razor?

查看:29
本文介绍了@: 在 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 中,@ 是相应的字符,它允许您在运行时 (或预编译)将被转换为 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 获取两个变量并将字符 - 放在它们之间,结果是一个内容块(或 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屋!

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