Creating a layered design in an application is a fundamental element of modern software architecture. The goal is to promote the Separation of Concerns (SoC) design principle. Separation of Concerns The ideas behind SoC date back to Dijkstra's 1974 paper "On the role of scientific thought" . In computer science, separation of concerns (sometimes abbreviated as SoC) is a design principle for separating a computer program into distinct sections. Each section addresses a separate concern, a set of information that affects the code of a computer program. A concern can be as general as "the details of the hardware for an application", or as specific as "the name of which class to instantiate". A program that embodies SoC well is called a modular program. Modularity, and hence separation of concerns, is achieved by encapsulating information inside a section of code that has a well-defined interface. - Wikipedia SoC is a broad design principal th...
Razor Pages are great for creating simple web applications. By default, a Razor Page should be compact, this often means a single Get and a single Post handler. This is usually sufficient for developing a basic CRUD style application. If your application needs more complex functionality, you may want to consider developing a Blazor or MVC ASP.NET application.
To deal with the scenario where a Razor Page needs multiple get/post handlers, ASP.NET provides the asp-page-handler action on the form tag. This can be combined with routing to enable multiple get/post handlers.
First, take a Razor Page and configure the routing to handle multiple get/post handlers as follow:
@page "{handler?}"
To create a form that calls the get/post handler, we can add the asp-net-handler action to the form as follows:
There is some "magic" in the naming conventions, in that the code method must start with OnGet or OnPost (depending on the form method), followed by the value you put in the asp-net-handler action.