How do I access the querystring value in a View?
-
never heard of anyone having the need to do such thing in asp.net mvc, probably you want to access it an Action cuz that's going to be really easyOmu– Omu2010-05-22 12:46:44 +00:00Commented May 22, 2010 at 12:46
-
1Are you sure you need query strings in MVC? Maybe give an example of what you want.Henk Holterman– Henk Holterman2010-05-22 12:46:49 +00:00Commented May 22, 2010 at 12:46
Add a comment
|
5 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.
Comments
In View, you can access it directly. No need to write any code in Controller, though you can.
For example - If your querystring has parameter named id, something like ?id=1
Razor syntax:
@Request.QueryString["id"]
1 Comment
Jonnie
Error CS0103 The name 'Request' does not exist in the current context