'.net 6 what is the proper way to add a form to a _Layout and handle the post

I need to add a subscribe form to my Layout so it is on all pages in the right side area.

How do I handle the post action as layouts dont have a codefile?

What I have so far is my layout has a signup partial and in that partial is the form. At this point I ponder what to do and what is the correct and safe way on handling user input and the action handler.



Solution 1:[1]

Create a Razor page e.g. Subscribe.cshtml that handles the form submission and specify that page in the asp-page attribute of the form tag helper:

<form method="post" asp-page="/Subscribe">

Process the submission in the OnPost handler of SubscribeModel.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Brind