Razor pages support has been added to asp.net core MVC which makes coding page-focused scenarios easier and more productive. Razor page support is enabled in Startup.cs file as
You must define Razor pages inside Pages folder to be able to make routing work correctly.
Razor pages skips the dependency of being routed via controllers and make use of existing features like Tag helpers, Html helpers as well as model bindings. A typical Razor Page will look like below:
@page directive must be the first razor directive on your page and it lets you skip the routing via controller, rather the page directive makes the entire file behave like an MVC action and thus it can receive request directly from IIS.
Razor can work as inline model as shown in above example in which case the code must be written in @function block or we can make Razor work in code behind syntax as well like in below example:
Here is how HelloWorld.cshtml will look like
And here goes HelloWorld.cshtml.cs