103
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.
Else and Else If
The @ (at) symbol is not require in else and else if statements.
// RazorControlStructure.cshtml
Output:
@switch Example
// RazorControlStructure.cshtml
Output:
@for
// RazorControlStructure.cshtml
Output:
It produces the following output.
Next TopicASP.Net Razor HTML Helpers