I used to see controller code like this:
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(CreateAccountViewModel model)
{
// save something
}
Both methods were named Create.
One had [HttpGet].
The other had [HttpPost].
And initially my brain went:
Why do we need two Create methods?
The easiest explanation is this:
GET
"Show me something."
POST
"Here is something."
What Does GET Mean?
A GET request usually asks the server for information.
For example:
User visits /Accounts/Create
↓
GET request
↓
Controller
↓
Return Create View
The action might be:
[HttpGet]
public IActionResult Create()
{
return View();
}
Its job is basically:
Show the Create Account page.
No account has been created yet.
The user is just asking for the form.
What Does POST Mean?
After the user fills out the form and clicks Create, the browser sends the form data back to the server.
That is commonly a POST request.
User completes form
↓
Clicks Create
↓
POST request
↓
Controller receives data
The action might look like:
[HttpPost]
public async Task<IActionResult> Create(
CreateAccountViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
// Save account
return RedirectToAction("Index");
}
Now the controller is no longer just displaying the form.
It is processing the submitted data.
The Complete Flow
USER
↓
GET /Accounts/Create
↓
CONTROLLER
↓
CREATE VIEW
↓
USER FILLS FORM
↓
POST /Accounts/Create
↓
CONTROLLER
↓
VALIDATE DATA
↓
SAVE DATA
↓
REDIRECT
That is why there can be two methods called Create.
They handle different HTTP requests.
How Does ASP.NET Know Which One to Use?
Because of these attributes:
[HttpGet]
and:
[HttpPost]
Even though both methods are called Create, ASP.NET Core can route the GET request to one method and the POST request to the other.
Conceptually:
GET Create
↓
[HttpGet] Create()
POST Create
↓
[HttpPost] Create(model)
What Does the HTML Form Do?
A Razor form might contain:
<form asp-action="Create" method="post">
<input asp-for="Name" />
<button type="submit">Create</button>
</form>
This part matters:
method="post"
That tells the browser to send a POST request when the form is submitted.
So the connection becomes:
<form method="post">
↓
HTTP POST
↓
[HttpPost]
↓
Controller action
Why Not Use GET to Save Data?
GET requests are supposed to retrieve information without changing application state.
For example:
GET /Accounts
might display a list of accounts.
But this would be a terrible design:
GET /Accounts/Delete/5
if simply visiting that URL immediately deleted account 5.
GET requests can be cached, bookmarked, crawled, or repeated.
That is not something I want happening to an action that changes important data.
A useful rule is:
GET = READ
POST = SUBMIT / CHANGE
There are more HTTP methods, such as PUT, PATCH, and DELETE, especially in APIs.
But GET and POST cover a huge amount of traditional MVC form work.
Why Redirect After a Successful POST?
You will often see this:
return RedirectToAction("Index");
instead of:
return View("Index");
One reason is something called the Post/Redirect/Get pattern.
The flow is:
POST
↓
Save data
↓
REDIRECT
↓
GET
↓
Display page
This helps prevent accidental duplicate submissions.
Imagine the user submits a transaction and then refreshes the browser.
If the browser is still sitting on the POST response, it may try to submit the same form again.
Redirecting to a GET page after saving helps avoid that problem.
The Anti-Forgery Token
ASP.NET Core forms often include protection against Cross-Site Request Forgery attacks.
You may see:
[ValidateAntiForgeryToken]
on a POST action.
For example:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(CreateAccountViewModel model)
{
}
Razor forms can generate a matching anti-forgery token.
The server checks that the form submission came from a valid request.
I think of it as another checkpoint:
Form
↓
POST
↓
Anti-forgery check
↓
Model validation
↓
Controller logic
A CRUD Example
CRUD stands for:
Create
Read
Update
Delete
A typical MVC controller could use GET and POST like this:
GET Index
Read list
GET Details
Read one item
GET Create
Show create form
POST Create
Create item
GET Edit
Show edit form
POST Edit
Update item
POST Delete
Delete item
That pattern shows up constantly in business applications.
What I Would Say in an Interview
If someone asked me:
“What is the difference between GET and POST?”
I would say:
GET is normally used to retrieve a resource or display a page without changing server state. POST sends data to the server and is commonly used for operations that create or change data, such as submitting an MVC form.
My memory trick:
GET
Give me the page.
POST
Here is my data.
That may be a simplified explanation, but it makes the controller flow much easier to understand.
