Getting familiar with Razor Pages
As its name implies, Razor Pages is a server-side way of rendering web content, organized by pages. That applies very well to the web, as people visit pages, not controllers. Razor Pages shares many components with MVC under the hood.
If you want to know if using MVC or Razor Pages is the best for your project, ask yourself if organizing your project into pages would be more suitable for your scenario. If yes, go Razor Pages; otherwise, pick something else, such as MVC or a SPA. We can also use both Razor Pages and MVC in the same application, so there is no need to choose only one.
Using Razor Pages is very similar to MVC. In the Startup.ConfigureServices
method, instead of services.AddControllersWithViews();
or services.AddControllers();
, we can call the services.AddRazorPages();
extension method.
The same applies to the Startup.Configure
method where we must map Razor Pages routes using the endpoints.MapRazorPages();
method.
The use...