---
title: "What is the difference between the HttpGet and HttpPost attributes in ASP.NET MVC?"  
description: "What is the difference between the HttpGet and HttpPost attributes in ASP.NET MVC?"  
author: "Revati S Misra"  
published: 2023-04-18  
updated: 2023-06-04  
canonical: https://www.mindstick.com/forum/157893/what-is-the-difference-between-the-httpget-and-httppost-attributes-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc", "mvc"]  
reading_time: 2 minutes  

---

# What is the difference between the HttpGet and HttpPost attributes in ASP.NET MVC?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between the [HttpGet](https://www.mindstick.com/forum/156917/when-to-use-httpget-and-httppost-method-with-actionresult-method-in-asp-dot-net-mvc) and HttpPost [attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging) in [ASP.NET MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc)?

## Replies

### Reply by Aryan Kumar

The HttpGet and HttpPost attributes in [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [MVC](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc) are used to control which HTTP methods can be used to call a controller action.

- **HttpGet** is used for actions that only need to read data from the server, such as displaying a list of items or retrieving a single item.
- **HttpPost** is used for actions that need to write data to the server, such as creating a new item or updating an existing item.

If no attribute is specified, the default is HttpGet.

Here is an example of how to use the HttpGet and HttpPost attributes:

C#

```plaintext
public class ProductsController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        // Get a list of products from the database.
        return View(products);
    }

    [HttpPost]
    public ActionResult Create(Product product)
    {
        // Create a new product in the database.
        return RedirectToAction("Index");
    }
}
```

In this example, the Index action can be called using either HTTP GET or HTTP POST. The Create action can only be called using HTTP POST.

The HttpGet and HttpPost attributes can also be used to restrict access to a controller action. For example, the following code would only allow authenticated users to call the Create action:

C#

```plaintext
[HttpPost]
[Authorize]
public ActionResult Create(Product product)
{
    // Create a new product in the database.
    return RedirectToAction("Index");
}
```

The HttpGet and HttpPost attributes are a powerful way to control how your controller actions can be accessed. By using these attributes, you can improve the security and usability of your ASP.NET MVC applications.


---

Original Source: https://www.mindstick.com/forum/157893/what-is-the-difference-between-the-httpget-and-httppost-attributes-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
