Skip to content

Add two OnGet method in a Razor page #32064

Discussion options

You must be logged in to vote

CoPilot suggests:
Certainly! In Razor Pages, you can define multiple handler methods for a single HTTP verb using a feature called named handler methods. This allows you to specify different methods to execute based on the route without relying on query string parameters or exposing the handler name in the URL.

Here’s how you can achieve this:

Named Handler Methods:
Named handler methods allow you to define multiple methods for the same HTTP verb (e.g., OnGet, OnPost) within your Razor Page.
These methods are executed based on the route and constraints, without exposing the handler name in the URL.
Usage Example: Let’s say you want to have two different OnGet handlers: OnGetAsync and OnGe…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Rick-Anderson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants