Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does @: mean in 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?

like image 801
Vivian River Avatar asked Mar 29 '16 16:03

Vivian River


People also ask

What is meaning of @: In .NET MVC?

Using @: to explicitly indicate the start of content We are using the @: character sequence to explicitly indicate that this line within our code block should be treated as content.

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 meant by Razor in MVC?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine.

What is @model in Razor?

New @model directive The @model directive provides a cleaner and more concise way to reference strongly-typed models from view files.


1 Answers

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

With @ you may write C# within HTML and with @: you may write HTML within C#.

Example:

@foreach (TestClass item in Model) {     @:@item.Code - @item.Name } 

Without the @: it wouldn't be possible to do this, since all the chars after the first @ will be considered as C#.

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)

like image 135
Leandro Soares Avatar answered Oct 04 '22 13:10

Leandro Soares