Let us learn all about Action Method with examples in ASP.NET MVC 5 through this article.
In this article, you will learn the following points about the Action Method in MVC 5.
- What is the Action Method in MVC 5?
- Type of Action method
- How to restrict the Action Method.
- How to call Action Method?
- How to change default Action Method?
- How does the default action get executed?
Following are the previous articles in ASP.NET MVC 5 series.
What is the Action Method in MVC 5
ASP.NET MVC action methods are responsible to execute the request and generate a response to it. All the public methods of the MVC Controller are action methods. If we want the public method to be a non-action method, then we can decorate the action method by “NonAction” attribute. It will restrict the action method to render on the browser.
To work with action method we need to remember the following points.
- The action method is the public non-static method.
- Action method can not be the private or protected method.
- Action method can not contain ref and out parameters.
- Action method can not be an extension method.
- Action method can not be overloaded.
Example of an action method in ASP.NET MVC 5 is as below.
- public class HomeController : Controller
- {
- // GET: Home
- public ActionResult Index()
- {
- return View();
- }
- }
You can see in the above action method example that the Index() method is a public method which is inside the HomeController class. And the return type of the action method is ActionResult. It can return using the “View()” method. So, every public method inside the Controller is an action method in MVC.
Action Method can not be a private or protected method.
- public class HomeController : Controller
- {
- // GET: Home
- private ActionResult Index()
- {
- return "This is Index Method";
- }
- }
If you provide the private or protected access modifier to the action method, it will provide the error to the user, i.e., “resource can not be found” as below.

An action method cannot contain ref and out parameters.
- public string Index(ref int id)
- {
- return "This is Index Method" +id;
- }
- public string Index(out int id)
- {
- id = 0;
- return "This is Index Method" +id;
- }
We can not provide the ref and out parameters to the action method. If you try to provide the ref and out parameters to the action method, then it will throw an error as below.

Action method can not be overloaded.



Himanjan PatiPosted Apr 24, 2020, 8:16 PM
Hello Shrimant, it is a nice artile but I suppose Methods in the Controller can be overloaded if we can specify the route attribute for the methods and passing the appropriate query string will be handled by the appropriate method.
Pankajkumar PatelPosted Aug 22, 2019, 4:01 AM
Nice article
Ritika GoswamiPosted Aug 22, 2019, 1:44 AM
Thanks for sharing such wonderful information keep sharing morehttps://www.exltech.in/dot-net-training.html