ASP.NET MVC应用程序< text>标签 [英] ASP.NET MVC application, <text> tag

查看:78
本文介绍了ASP.NET MVC应用程序< text>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的ASP.NET MVC应用程序中,.cshtml文件中使用了<text>标记.

In an ASP.NET MVC application I am working on, <text> tags are being used in a .cshtml file.

示例-

<text>some text</text>

它们提供什么功能?我在互联网上找不到对它们的任何引用:)

What functionality do they provide? I can not find any reference to them on the interweb :)

谢谢!

推荐答案

与@标记有点相反...

The are kinda the opposite of the @ tags...

处于"HTML模式"的视图中为标准视图,然后可以使用像这样的Razor块:

Standard in views you are in "HTML-mode", you can then use a Razor-block like this:

@{
  //Razor code
}

Razor将在剃刀块中检测HTML标记并将其呈现,但有时您只需要显示文字即可.这就是标签的所在位置...它可以切换回HTML模式,而无需使用实际的HTML标签...

Razor will detect HTML-tags in a razor block and render that but sometimes you just need to show the literal text. That's where the tag comes in... It switches back to HTML-mode without using an actual HTML-tag...

因此,某些文本将在您的视图中呈现该精确文本(不带标记>): 有帮助的示例,但是此代码:

So some text will render that exact text (WITHOUT the tag>) in your view: Convaluted example, but this code:

<div>
you have
@{
 if(numItems == 0)
 {
   <text>no</text>
 }
 else
 {
   @numItems
 }


}
items
</div>

例如将呈现您没有项目"或您有5个项目" ...

Will render "You have no items" or "you have 5 items" for example...

这篇关于ASP.NET MVC应用程序&lt; text&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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