MVC 4: Passing Query String Values Within a View

Building Links from Model Data

This article illustrates how to build a link within an MVC view which passes model data as a query string variable.

First, I begin with my “model” statement exposing my RaveUser model’s properties.
1.MVC-4---passing-query-string-values-within-a-view

Next, I provide an ActionLink() statement with text for the link (“Reload All Values”), the name of the controller function to call (“LoadSelectedUser”), and finally, pass to the ActionLink() statement the SNumber property of the model.
2.MVC-4---passing-query-string-values-within-a-view

As you can see, when the page displays and the Razor engine renders the HTML, the link displays as expected, passing the current user’s SNumber (1-8) as the query string value.
3.MVC-4---passing-query-string-values-within-a-view

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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