You can use the exactsame syntax as you would with a Razor view, but there's something more; a Razor page inherently hasaPageModelclassassociated withit—notice the@modeldirective pointing toHelloWorldModel. This class must inherit fromPageModel, and in it, you can define methods for handling HTTP methods, such asGETorPOST. The file containing the definition of the page model class must have the same physical name as the Razor page with a.csextension, be located in the same folder, and inherit fromPageModel. So, for example, if the previous file was namedHelloWorld.cshtml, then its page model would go in aHelloWorld.cshtml.csfile:
public class HelloWorldModel : PageModel
{
}
If you do not wish to specify a custom page model class, one is provided for you automatically, and you can still specify handler methods directly in the.cshtmlfile:
@functions
{
public async Task<IActionResult> OnGetAsync()
{
if...