Getting started with Razor Pages

Razor pages is a new asp.net feature, available in .net core 2.0 that allows us to create pages without some of the overhead that MVC requires. Razor pages are intended to replace MVC controllers that look like this:

public IActionResult About() {
return View();
}

By loading MVC we get the Razor pages feature for free. All we need to do to create a new page is put some .cshtml (for example about.cshtml) inside a new folder called Pages, and put @page on top of this file.

For example: (Pages/About.cshtml):

@page
This is a RazorPage!

If we want to navigate to this page, we simply can by going to /About

We can use the same layout we already are using for our MVC-controller by setting the layout like this:

@{ Layout = "_Layout"; }