MVC Action Parameter
Action method parameter are values which are retrieved from the request data collection. The data Collection involves values from the URL, Query String & Cookie values. Action method parameters values get automatically mapped from the URL parameter. MVC Support optional parameters,they are automatically converted into null.
ASP.NET application that do not use MVC framework,user interaction is organized around pages.Likewise user interaction among ASP.NET MVC application is around controllers and action methods.Controller defines action method and it can define as many methods as it needs. Controller actions are like any other method. In fact, a controller action can even specify parameters that ASP.NET MVC populates, using information from the request, when it executes.
The following example shows a controller class with Helloworld action method.
Action Method Parameters
The values for action method parameters are retrieved from the request's data collection. Name/values pairs for form data, query string values, and cookie values are included in data collection.
There are two functions for Controller class,first is locates the action method and next is determines any parameter values for the action method.Null is passed as the parameter value,when the
parameter value cannot be parsed, and the type of the parameter is a reference type or a nullable value type. Otherwise, an exception is thrown.
Automatically Mapping Action Method Parameters
For action methods, MVC framework automatically map URL parameter values to parameter values. If an action method takes a parameter, the MVC framework examines incoming data and check whether the request data contains an HTTP request value with the same name. If the request contain the same name the request value is automatically passed to the action method. The following example the parameter(label) is assumed to map to a request value that is also named label. Because of this automatic mapping, the action method does not have to include code to get a parameter value from the request.