Action Methods are like any other method of a class and typically have a one-to-one mapping with user interactions. when a user enters a URL into the Browser in client-side then MVC App uses routing rules which are defined in the Global.aspx in the server-side to parse the URL and to exactly checks the path of the controller. and handles the requests in the controller with appropriate Action methods. and all the methods of a controller class are called Action Methods. the Action Methods have some restrictions as below:
- Action Methods must be Public.
- ActionResult is the superclass of all the return type action methods in MVC
- it can not have open generic types.
- it can not be overloaded
- it can not be constructor, setter, getter
- it can not be a static method.
- action method can not be an extension method
- every controller has at least one default Index() method and returns the View page.
Asp.net MVC ActionResult :
various types of action results are available in asp.net MVC as shown below.
- ViewResult --> It returns the View
- RedirectResult --> it returns to specific URL
- RedirectToRoutResult --> it redirects to action controller
- PartialViewResult --> receives as a response for view engine
- JsonResult --> it returns the JSON Result
- JavaScriptResult --> it returns the Json Result
- FilePathResult --> it returns the file content
- ContentResult --> it returns the string
- EmptyResult -->it returns the nothing
Example of Action Method :
public class ATGController : Controller
{
public ActionResult AllTechGeeks()
{
ViewData["atg"] = "All Tech Geeks";
return View();
}
}
|
---|
The Following Image explains briefly about Action Methods.
Post a Comment (0)