Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 22 January 2015
Keywords : Action Parameters in MVC,Action parameters,beginners,Tutorial for MVC,Tutorial

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.

Action Methods

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.

Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.