Javatpoint Logo
Javatpoint Logo

ASP.NET Razor Control Structures

Control structures are control statements that are used to control program flow. C# programming language uses if, else, if else, switch, for, foreach, while to perform conditional logic in the application.

Razor engine supports all these controls in the view file. Let's see some examples that implements control structure using razor syntax.


@if

// RazorControlStructure.cshtml

Output:

It produces the following output.

ASP Razor control structure 1

Else and Else If

The @ (at) symbol is not require in else and else if statements.

// RazorControlStructure.cshtml

Output:

ASP Razor control structure 2

@switch Example

// RazorControlStructure.cshtml

Output:

ASP Razor control structure 3

@for

// RazorControlStructure.cshtml

Output:

It produces the following output.

ASP Razor control structure 4





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA