In Razor you can create blocks of code nearly anywhere using @{ }.
A block of code doesn’t emit anything into the output, but you can use the block to manipulate a model, declare variables, and set local properties on a view. Be extremely careful about having too much code in a view, however, because it’s not the best place for logic.
@{ var message = "Hello, World!"; } @for (var i = 0; i < 10; i++) { <div> @message </div> }
If you want to mix Code & Text then you must use @:
Use @: to switch from C# into text.
@foreach(var item in Model) { @:Item: @item }
Comments in Razor can start with @* and end with *@. Nothing inside a comment will execute or appear in the output, not even HTML markup.
@* <span>You won't see any of this</span> @foreach(var item in Model) { @:Item: @item } *@