Here we will learn what are the action methods in asp.net mvc and how to define URLs for action method in asp.net mvc with example.
Let’s start understanding what the Action method is? When any user wants to access a website or application in asp.net mvc user will enter URL in the browser like as shown below.
In the above URL, you can see that PersonDetails is controller, and Index is an action method in which the user is entering to invoke the action method index by entering the mentioned URL in the browser.
When the controller gets a request by the browser, the controller will invoke the method inside of it. If the method is not found in the controller, it will popup error, saying HTTP has not found an exception.
The method with ActionResult in asp.net mvc is called Action Methods, and it will return various View Results. For example, the following is the PersonDetailsController code snippet. You will see that the Controller is a Class, and Index is a Method inside that class. Here Index is the action method of PersonDetailsController.
public class PersonDetailsController : Controller
// GET: /PersonDetails/
public ActionResult Index()
This is how we can define action methods and URLs for action methods in asp.net mvc application.