Wednesday 20 May 2015

Action result And Action Method in MVC

Here we will learn about the action result and action method in Asp.net MVC.
Action Method :- This Action method is use to transfer the information means execute the response and give the output and generate the output.
By default it gives the output in”Action Result” form.
Will take an example for understanding this, When a end user type a url then “Asp.Net MVC life cycle” use route to create a route.config or we can say “Global.asax for getting the path of action method which to be executed.

Suppose a user enter URL like “http://dotnet-munesh.blogspot.in/”

When user run this url it execute action method which is specified in “Route.config” file  with as default action method and the default controller, For checking in “Route.config” file contain a method “RegistersRoutes” there we can check this.
If user type “http://dotnet-munesh.blogspot.in/Tutorial”

It means it execute default action method and a with “Tutorial” Controller.

If user type http://dotnet-munesh.blogspot.in/Tutorial/MVCTutorial

it means it execute MVCTutorial method from Tutorial controller.

If URL is ://dotnet-munesh.blogspot.in/Tutorial/MVCTutorial/1

Then here method is MVCTutorial and this method pass ID also.
So this is concept of MVC Action method.
Action Result :- Action Result is an abstract class which is define in “System.Web.MVC” namespace. Almost all the Action method return a object of the class which is derived from “ActionResult” class, that define the MVC Action method.
In MVC mostly Action method return a view which is the instance of “ViewResult” Class.
See following example where A Action method  is returning View
public ActionResult Index()
{
    return View();
}


We can also create Custom ActionResult return type using creating a class and by deriving “ActionResul”  abstract class.
Action result Return Type : - Action result in MVC is the return type for a controller method. This Action result return “File Streams”, Modal to view, and this also redirect to another  controller method.


No comments:

Post a Comment

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...