ASP.NET MVC

Understanding Action Methods in MVC Razor

Understanding Action Methods in MVC Razor

Action Methods in MVC

Action method
All the public methods of the Controller class are called Action methods. They are like any other normal methods with the following restrictions:
Action method must be public. It cannot be private or protected
Action method cannot be overloaded
Action method cannot be a static method.


Default Action Method
Each controller may have a default action method that corresponds to the route that has been set up in the RouteConfig class. According to the set default root, the Index() method is the default action method for any controller.

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}/{name}",
    defaults: new { controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional
            });

However, you can change the default action name as per your requirement in the RouteConfig class.







Related Post

About Us

Community of IT Professionals

A Complete IT knowledgebase for any kind of Software Language, Development, Programming, Coding, Designing, Networking, Hardware and Digital Marketing.

Instagram