Obviously the Request object is too complicated to be used
for most of the interactions between the view and the controller. The ASP.NET
MVC team of course built in some methods of obtaining data with strongly-typed
access to the values posted by the form. When these values are posted back to the
server they are inserted in to the controller by intelligently assigning the
values based on the names given to the controls and the controller parameters.
This allows MVC to pass the posted values into parameter variables used by the
To demonstrate this, we will use another controller action.
This time we will use parameters to get access to our data, so we will have
three parameters in our controller action this time: firsName, middleName, and
lastName. We will perform our logical operations on these parameter variables.
Listing 5: Obtaining data from the parameters
public ActionResult DisplayUserData2(string firstName,
string middleName, string lastName)
ViewData["FirstName"] = firstName;
ViewData["MiddleName"] = middleName;
ViewData["LastName"] = lastName;
Notice that we now use strongly-typed parameters instead of
the strings passed to the Request.Form variable. The ASP.NET MVC framework is
handling the mapping of the values passed in the form data onto these
controller parameter variables.
When observing the results we receive when using this
controller action, we see a similar result.
Figure 8: Display view with parameter mapped data