Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access querystring in ASP.Net MVC View?

How do I access the querystring value in a View?

like image 493
Fraz Sundal Avatar asked May 22 '10 12:05

Fraz Sundal


People also ask

Can we use query string in MVC?

MVC framework automatically converts a query string to the action method parameters provided their names are matching. For example, the query string id in the following GET request would automatically be mapped to the Edit() action method's id parameter. This binding is case insensitive.

How do you use a QueryString?

A Query String Collection is used to retrieve the variable values in the HTTP query string. If we want to transfer a large amount of data then we can't use the Request. QueryString. Query Strings are also generated by form submission or can be used by a user typing a query into the address bar of the browsers.


1 Answers

It is not a good design to access query parameters in a view. The view should use the model provided by the controller. So the controller reads query parameters and passes them to the view. If you want to ignore this rule you could always do this in your view:

<%= Request["SomeParameter"] %> 

But I would strongly discourage you from doing so.

like image 76
Darin Dimitrov Avatar answered Oct 05 '22 04:10

Darin Dimitrov