Action Method in Asp.net MVC Controller

Action Method in Asp.net MVC Controller:




In ASP.NET applications that do not use the MVC framework, user interaction is organized around pages, and around raising and handling events from the page and from controls on the page. In contrast, user interaction with ASP.NET MVC applications is organized around controllers and action methods. The controller defines action methods. Controllers can include as many action methods as needed.

Action methods typically have a one-to-one mapping with user interactions. Examples of user interactions include entering a URL into the browser, clicking a link, and submitting a form. Each of these user interactions causes a request to be sent to the server. In each case, the URL of the request includes information that the MVC framework uses to invoke an action method.

Action Method in Asp.net MVC:

When a user enters a URL into the browser, the MVC application uses routing rules that are defined in the Global.asax file to parse the URL and to determine the path of the controller. The controller then determines the appropriate action method to handle the request. By default, the URL of a request is treated as a sub-path that includes the controller name followed by the action name.


The following example shows a controller class that has a HelloWorld action method.

 public class MyController : Controller
     {
     public ActionResult HelloWorld()
     {
        ViewData["Message"] = "Hello World!";
        return View();
     }
     }


 Asp.net Related Post:




Comments

Post a Comment