GetandPost.md - brainchildservices/curriculum GitHub Wiki
Slide 1
WHAT IS THE DIFFERENCE BETWEEN GET AND POST; HOW TO CONTROL GET AND POST:
-
A Get Request is generally used to get data from the web server. A GET request is generally issued,
- When you click on a hyperlink
- When Response.Redirect() statement is executed
- When you type URL in the address bar and hit enter
Slide 2
-
POST Request is generally used to submit data to the server. A POST request is generally issued,
- When you click on a submit button
- When AUTOPOST back is set true and when a selection in the DropDownList is changed
-
Http Handler Methods:
- Handler methods in Razor Pages are also based on naming conventions.
- The basic methods work by matching HTTP verbs used for the request to the name of the method, and they are prefixed with "On": OnGet(), OnPost(), OnPut() etc.
- They also have asynchronous equivalents: OnPostAsync(), OnGetAsync() etc.
Slide 3
-
OnGet is called on a Razor Page to initialize the state for the page.
- When the page is first navigated to, the required page as per the URL given by the user, content is displayed because the HTTP GET verb was used for the request, firing the OnGet() handler.
-
OnPost()
- 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 sent from the Razor Page through Model class object received as parameter.