MVC: Action Methods with Parameters

Please see my other MVC articles.

Passing arguments to action methods.

It’s often necessary when calling an action method to pass to it variables necessary for business logic.
In this article, I will illustrate one method that is similar to the Web Forms programming model of using the question mark + equals sign convention (?VariableName=Value).

To begin, I first created a simple HelloWorld controller in which I placed an action method “Welcome().”
Notice that this method receives two parameters, “name” and “numTimes.”


Now I’ll run my application while passing the variables “?name=earnie&numtimes=4.”
As you can see, the Welcome() method parsed my name and the number of times I wished to display a welcome message to myself.


Also, I may elect to use an action method that returns a simple string result instead of a View.


When I execute the action method, you can see the results are similar.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s