---
title: "How can we restrict MVC actions to be invoked only by GET or POST?"  
description: "How can we restrict MVC actions to be invoked only by GET or POST?"  
author: "Anupam Mishra"  
published: 2016-02-14  
updated: 2016-02-14  
canonical: https://www.mindstick.com/forum/33977/how-can-we-restrict-mvc-actions-to-be-invoked-only-by-get-or-post  
category: "asp.net"  
tags: ["c#", "asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# How can we restrict MVC actions to be invoked only by GET or POST?

Hi All,How can we restrict [MVC](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc) [actions](https://www.mindstick.com/forum/156060/what-are-the-actions-performed-by-sql-server) to be invoked only by GET or [POST](https://www.mindstick.com/articles/12829/aspects-that-make-australia-post-shipping-extension-a-useful-tool)? Please give me a solution.\
thanx.

## Replies

### Reply by Anupam Mishra

I have got it, its answer. Details explanation is below:We can restrict the MVC action with the **HttpGet** or **HttpPost** attribute to restrict the type of **HTTP** calls. For example,In below code **DisplayStudent** action can only be invoked by HttpGet. If we try to make HTTP POST on **DisplayStudent**, it will throw an error.\
\

```
[HttpGet]public ViewResult DisplayStudent(int id){    Student objStudent = Studentss[id];    return View("DisplayStudent",objStudent);} 
```


---

Original Source: https://www.mindstick.com/forum/33977/how-can-we-restrict-mvc-actions-to-be-invoked-only-by-get-or-post

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
