| Sania Uzair
What are Razor Pages?
ASP.NET Razor Pages is a server-side, page-focused framework that enables constructing dynamic, data-driven web sites with clean separation of concerns. It was first introduced as part of ASP.NET Core and is currently included in.NET 5. Razor Pages, which is part of Microsoft's ASP.NET Core web development framework, offers cross-platform development and can be deployed on Windows, Unix, and Mac operating systems.
Razor syntax:
A Razor content page serves as a starting point for creating HTML. Static HTML, tag helpers that dynamically emit HTML, and C# code are all common components of a content page. According to a set of conventions, or syntax, the C# code is placed within the static content and tag helpers.
All code blocks must be enclosed by @{.... } brackets. You're assumed to have started writing C# code as soon as you type @. Unless you tell Razor otherwise, everything that follows is assumed to be code:
- @{
- var numbers = Enumerable.Range(1, 10); //Get numbers from 1 - 10
- foreach(var num in numbers){
- ...
- }
- }
Variable values are prefixed with the @ symbol before being turned into HTML:
- The time is @DateTime.Now
If you want to render the variable number from the previous example within the loop, you must precede it with a @ sign:
- @{
- var numbers = Enumerable.Range(1, 10); //Get numbers from 1 - 10
- foreach(var number in numbers){
- @number
- }
- }
Typically, statements will be declared in a code block separate from the Razor code that renders them. When used to control rendering, iteration and selection statement keywords (if, for, foreach, switch, while, etc.) do not require curly braces. A simple @ symbol will suffice. The same is true for try... catch.
Conclusion:
Razor Pages has the advantage of collecting everything connected to a specific request in one place. It has specific codes behind individual pages and is more organized..
Join us next time, as we continue our journey of learning canvas apps.Click here to learn more about Imperium's Power Apps Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.