In this article I will explain with an example, how to use the OnPost handler method in ASP.Net Core Razor Pages.
The OnPost handler method is used for handling Form Submissions and the name of the OnPost handler method is specified on the Submit Button used to submit the Form using the asp-page-handler attribute in ASP.Net Core Razor Pages.
Note: For beginners in ASP.Net Core Razor Pages, please refer my article ASP.Net Core Razor Pages: Hello World Tutorial with Sample Program example.
Following is a Model class named PersonModel with two properties i.e. FirstName and LastName.
public class PersonModel
    public string FirstName { get; set; }
    public string LastName { get; set; }
Razor PageModel (Code-Behind)
The PageModel consists of two Action Handler methods.
Handler method for handling GET operation
This Handler method handles the GET calls, for this particular example it is not required and hence left empty.
Handler method for handling Button Click and POST operation
This Handler method handles the POST call when the Submit Button is clicked and the Form is submitted.
The Handler method for POST operation accepts the values of First Name and Last Name sent from the Razor Page through PersonModel class object received as parameter.
Finally, the values are assigned to the Name property which is later displayed on the Razor Page.
public class IndexModel : PageModel
    public string Name { get; set; }
    public void OnGet()
    public void OnPostSubmit(PersonModel person)
        this.Name = string.Format("Name: {0} {1}", person.FirstName, person.LastName);
Razor Page (HTML)
The HTML of Razor Page consists of an HTML Form with two TextBox elements and a Submit Button.
The Submit Button has been set with the POST Handler method using the asp-page-handler attribute.
Note: In the Razor PageModel, the Handler method name is OnPostSubmit but here it will be specified as Submit when calling from the Razor HTML Page.
Finally, the value of the Name property is displayed using Razor syntax.
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@model Razor_Form_Submit.Pages.IndexModel
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width"/>
    <form method="post">
                <td>First Name: </td>
                <td><input type="text" id="txtFirstName" name="FirstName"/></td>
                <td>Last Name: </td>
                <td><input type="text" id="txtLastName" name="LastName"/></td>
                <td><input type="submit" value="Submit" asp-page-handler="Submit"/></td>
Using the OnPost handler method in ASP.Net Core Razor Pages