Home > Blockchain >  What is a basic difference between OnGet and OnPost?
What is a basic difference between OnGet and OnPost?

Time:09-12

Use case: I have a button on an Index page that should run an action that sends a GET request to get data from an outside source and add it to the DB, and then reload the page including the new data.

On one hand I am GETting data, on the other I am POSTing the data into the DB.

CodePudding user response:

Hard to answer your question without any context - I have no idea what your code looks like. Having said that, this sounds like a GET. A POST means that the client is sending data to the server. In your case, no values are being sent to the server from the client. What is happening, is that the client is retrieving data from the outside source (classic GET), and then that data is being sent from that outside source to a database on the server. Nowhere in this workflow is there any data being sent from the client to the server (which would warrant POST).

CodePudding user response:

Firstly,you can use the following code to send a get request when clicking the button:

<form method="get">
    <input type="submit" value="submit" />
 </form>

handler:

public IActionResult OnGet()
        {
            //get data from an outside source and add it to the DB
            return Page();
        }

With return Page();,it will reload the page with new data.

  • Related