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.
Action Methods & URLs
Let’s start understanding what Action method is? when any user want to access website or application in asp.net mvc user enter URL in browser like as shown below
In above URL you can see that Student is controller and Index is action method which user is entering to invoke action method index by enter this URL in browser.
The general format of URL is as given below:
Here id is the optional parameter.
When controller gets request by browser that controller will invoke method inside it . In case if method not found in controller then it will popup error saying http not found exception.
Controller with Action Methods in Asp.Net MVC
The method with ActionResult in ASP.NET MVC is called as Action Methods which return various View Results. For example following is the StudentController code snippet. You will see that Controller is a Class and Index is a Method in side that class. Here Index is the action method of StudentController.