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?
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.
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. }
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.
New @model directive The @model directive provides a cleaner and more concise way to reference strongly-typed models from view files.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With