Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between @: and <text> in Razor

What's the difference between these 2 in Razor? I find that I can accomplish the same, whether I use @: or <text>.

like image 570
anemaria20 Avatar asked May 20 '16 14:05

anemaria20


People also ask

What does @: mean in Razor?

The @: sequence indicates that the line of content that follows should be treated as a content block: ("razor at colon" in Google).

What is @: In Cshtml?

This operator is useful in conjunction with other Razor server side operators when you want to output something as a literal text. For example: @if (model. Foo) { @:Some text to be written directly. }

What is the difference between Razor view and Razor page?

The difference between them is that View Pages are Razor views that are used to provide the HTML representations (aka views) for services in much the same way View Pages work for MVC Controllers.

What is difference between MVC and Razor pages?

A Razor Page is almost the same as ASP.NET MVC's view component. It has basically the syntax and functionality same as MVC. The basic difference between Razor pages and MVC is that the model and controller code is also added within the Razor Page itself. You do not need to add code separately.


1 Answers

Scott Guthrie wrote about both on his blog. His answer basically boils down to <text> supports multiple lines, while @: is meant to be a more compact form for a single line.

like image 136
vcsjones Avatar answered Sep 28 '22 10:09

vcsjones