---
title: "Define Action Selector in MVC."  
description: "Define Action Selector in MVC."  
author: "Anonymous User"  
published: 2020-01-30  
updated: 2020-01-30  
canonical: https://www.mindstick.com/forum/155765/define-action-selector-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 3 minutes  

---

# Define Action Selector in MVC.

[Please explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true) to me what is Action Selector in [Asp.Net MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) with an example.

## Replies

### Reply by Nishi Tiwari

**[ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) MVC Action Selectors**

Action selectors are the attributes that are applied to the action methods of a controller. It is used for selecting the correct action method to call as per the request given. [**MVC gives the two action selector attributes:**](https://www.mindstick.com/forum/155764/explain-action-method-parameter)

1. ActionName

2. Action Verbs

## ActionName

This attribute will allow us to specify a different name for the action method. It is most useful when we want to call action by a different name.

For Example

We are using the ActionName attribute to give different names for the index action method. The controller code will look like this:

## // MusicStoreController.cs

```
1.	using System;
2.	using System.Collections.Generic;
3.	using System.Linq;
4.	using System.Web;
5.	using System.Web.Mvc;
6.	namespace MvcApplicationDemo.Controllers
7.	{
8.	    public class MusicStoreController : Controller
9.	    {
10.	        [ActionName("store")]
11.	        public ActionResult Index()
12.	        {
13.	            return View();
14.	        }
15.	    }
16.	}
```

Now, we need to create a view in the MusicStore folder with the same name as the ActionName. So, we have created a store.cshtml file which has the following code.

## // store.cshtml

```
1.	@{
2.	    ViewBag.Title = "store";
3.	}
4.	<h2>Hello, This is Music store.</h2>
```

Output:

The following output will be produced when action will be called with a different name that is"store".

![Define Action Selector in MVC.](https://www.mindstick.com/mindstickforums/f10a6730-d857-48e1-bd85-d5723b2e77c8/images/c170740e-e7da-4d8f-a947-b4df3c67309c.png)

## ActionVerbs

ASP.NET MVC also provides action verbs that are applied to the action methods and works for HttpRequest methods. There are various ActionVerbs which are listed below.

o HttpPost

o HttpGet

o HttpPut

o HttpDelete

o HttpOptions

o HttpPatch

ActionVerbs are the name of the HTTP requests which a controller will handle. We can use it for selecting the action methods.

## Example

In this example, we are trying to access an index action by get request, which will be accessible only for HTTP post requests. The controller code may look like this:

## // MusicStoreController.cs

```
1.	using System;
2.	using System.Collections.Generic;
3.	using System.Linq;
4.	using System.Web;
5.	using System.Web.Mvc;
6.	namespace MvcApplicationDemo.Controllers
7.	{
8.	    public class MusicStoreController : Controller
9.	    {
10.	        [HttpGet]
11.	        public ActionResult Index()
12.	        {
13.	            return View();
14.	        }
15.	        [HttpPost]
16.	        public ActionResult Welcome()
17.	        {
18.	            return View();
19.	        }
20.	    }
21.	}
```

The Index file for MusicStoreController.

## // index.cshtml

```
1.	<div class="jumbotron">
2.	    <h2>Welcome to the music store.</h2>
3.	</div>
```

## Output:

It will produce the following output when the index action will be called.

![Define Action Selector in MVC.](https://www.mindstick.com/mindstickforums/f10a6730-d857-48e1-bd85-d5723b2e77c8/images/2a982131-9f61-46b5-a233-6985cd0b3cc2.png)

It will produce the error message when we make a get a request for the store action method.

![Define Action Selector in MVC.](https://www.mindstick.com/mindstickforums/f10a6730-d857-48e1-bd85-d5723b2e77c8/images/19ec8782-dc45-4f84-a322-b6ffdffee79e.png)


---

Original Source: https://www.mindstick.com/forum/155765/define-action-selector-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
