Explain me about Action Method with using URL and also with example in MVC.
Define Action Method in MVC
32928-Jan-2020
Updated on 28-Jan-2020
Home / DeveloperSection / Forums / Define Action Method in MVC
Explain me about Action Method with using URL and also with example in MVC.
Nishi Tiwari
28-Jan-2020Action method
All the public methods of a Controller class are known as Action methods. They are similar to any other normal methods having the following restrictions:
1. Action method must be public. It cannot be private or protected
2. Action method cannot be overloaded
3. Action method can never be a static method.
4. Every controller has at least one default Action method Index() that returns the view page.
5. ActionResult is a base class of all the result type action methods.
This is an example of Index action method of StudentController
As we can see in the above example, Index method is a public method and it returns ActionResult using the View() method and The View() method is defined in the Controller base class, which returns the ActionResult.
Action Methods & Urls in Asp.Net MVC
When any user want to access website or any application in asp.net mvc user enter its URL in browser
E.g. http://localhost:7575/PersonDetails/Index
In above URL we can clearly see that PersonDetails is controller and Index is action method which user may entering to invoke action method index by enter this URL in browser.
When controller gets request by the browser that controller will invoke method inside it. In case in which method not found in controller then it will show error saying http not found exception.
Controller with Action Methods in Asp.Net MVC
The method with the ActionResult in asp.net mvc is known as Action Methods which return various View Results. For example given below we will see that Controller is a Class and Index is a Method in side that class. Here Index is the action method of PersonDetailsController
This is how we can easily define action methods and urls for action methods in asp.net mvc application.