diff --git a/aspnetcore/mvc/views/razor.md b/aspnetcore/mvc/views/razor.md index b0e729a8cf13..957a60196bcb 100644 --- a/aspnetcore/mvc/views/razor.md +++ b/aspnetcore/mvc/views/razor.md @@ -26,7 +26,7 @@ When an `@` symbol is followed by a [Razor reserved keyword](#razor-reserved-key To escape an `@` symbol in Razor markup, use a second `@` symbol: -```cshtml +```razor
@@Username
``` @@ -38,11 +38,10 @@ The code is rendered in HTML with a single `@` symbol: HTML attributes and content containing email addresses don't treat the `@` symbol as a transition character. The email addresses in the following example are untouched by Razor parsing: -```cshtml +```razor Support@contoso.com ``` - :::moniker range=">= aspnetcore-6.0" ### Scalable Vector Graphics (SVG) @@ -69,20 +68,20 @@ HTML attributes and content containing email addresses don't treat the `@` symbo Implicit Razor expressions start with `@` followed by C# code: -```cshtml +```razor@DateTime.Now
@DateTime.IsLeapYear(2016)
``` With the exception of the C# `await` keyword, implicit expressions must not contain spaces. If the C# statement has a clear ending, spaces can be intermingled: -```cshtml +```razor@await DoSomething("hello", "world")
``` Implicit expressions **cannot** contain C# generics, as the characters inside the brackets (`<>`) are interpreted as an HTML tag. The following code is **not** valid: -```cshtml +```razor@GenericMethod
Last week this time: @(DateTime.Now - TimeSpan.FromDays(7))
``` @@ -115,7 +114,7 @@ The code renders the following HTML: Explicit expressions can be used to concatenate text with an expression result: -```cshtml +```razor @{ var joe = new Person("Joe", 33); } @@ -127,7 +126,7 @@ Without the explicit expression, `Age@joe.Age
` is treated as an email add Explicit expressions can be used to render output from generic methods in `.cshtml` files. The following markup shows how to correct the error shown earlier caused by the brackets of a C# generic. The code is written as an explicit expression: -```cshtml +```razor@(GenericMethod
Now in HTML, was in C# @inCSharp
@@ -225,7 +224,7 @@ The default language in a code block is C#, but the Razor Page can transition ba To define a subsection of a code block that should render HTML, surround the characters for rendering with the Razor `The value was even.
@@ -320,7 +319,7 @@ Control structures are an extension of code blocks. All aspects of code blocks ( `else` and `else if` don't require the `@` symbol: -```cshtml +```razor @if (value % 2 == 0) {The value was even.
@@ -337,7 +336,7 @@ else The following markup shows how to use a switch statement: -```cshtml +```razor @switch (value) { case 1: @@ -356,7 +355,7 @@ The following markup shows how to use a switch statement: Templated HTML can be rendered with looping control statements. To render a list of people: -```cshtml +```razor @{ var people = new Person[] { @@ -371,7 +370,7 @@ The following looping statements are supported: `@for` -```cshtml +```razor @for (var i = 0; i < people.Length; i++) { var person = people[i]; @@ -382,7 +381,7 @@ The following looping statements are supported: `@foreach` -```cshtml +```razor @foreach (var person in people) {Name: @person.Name
@@ -392,7 +391,7 @@ The following looping statements are supported: `@while` -```cshtml +```razor @{ var i = 0; } @while (i < people.Length) { @@ -406,7 +405,7 @@ The following looping statements are supported: `@do while` -```cshtml +```razor @{ var i = 0; } @do { @@ -422,7 +421,7 @@ The following looping statements are supported: In C#, a `using` statement is used to ensure an object is disposed. In Razor, the same mechanism is used to create HTML Helpers that contain additional content. In the following code, HTML Helpers render a `