Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC application, <text> tag

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!

like image 930
A Bogus Avatar asked Feb 18 '23 13:02

A Bogus


2 Answers

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...

like image 65
Céryl Wiltink Avatar answered Feb 27 '23 12:02

Céryl Wiltink


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

like image 27
Oleksii Aza Avatar answered Feb 27 '23 12:02

Oleksii Aza