Reputation: 3930
In an ASP.NET MVC application I am working on, <text>
tags are being used in a .cshtml
file.
Example -
<text>some text</text>
What functionality do they provide? I can not find any reference to them on the interweb :)
Thanks!
Upvotes: 4
Views: 11023
Reputation: 1909
The are kinda the opposite of the @ tags...
Standard in views you are in "HTML-mode", you can then use a Razor-block like this:
@{
//Razor code
}
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>
Will render "You have no items" or "you have 5 items" for example...
Upvotes: 6
Reputation: 18639
The <text>
explicitly tells the Razor view engine that this is text and not code. I use it when the renderer struggles with the page or if the html needs to be tightly controlled.
For example
<div id="content" @if (ViewData["PageLayout"] != null){
<text>class="@ViewData["PageLayout"].ToString()</text><text>"</text>
}>
See this post from Scott Gu.
Upvotes: 0
Reputation: 5398
This element for identifying content explicitly. You can read information about this here: http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx
Upvotes: 2