ASP.NET RazorLesson 23Free preview
Razor C# Logic
This lesson is part of ASP · All levels
Summary
C# branch logic such as if, else, and switch can be written directly into a Razor page to display content according to the condition. Writing conditions using operators such as ==, >, &&, and notation is applicable in the same way as in ordinary C# programs. With branching, a page can display different messages, menus, or views for each data state.
Key points
- If and else controls which HTML blocks are rendered.
- The comparison operator uses == for the equivalent, not a single sign =.
- Logical operator && for AND and notation for OR.
- Otherwise, it's used to test several conditions in succession.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.