Home > DeveloperSection > Forums > how to access query string value in ASP.Net MVC View
Sachin Singh
Sachin Singh

Total Post:26

Points:182
Posted on    March-14-2016 12:18 AM

 ASP.Net C#  ASP.Net  ASP.NET MVC  HTML5  View  CSS 
Ratings:


 1 Reply(s)
 281  View(s)
Rate this:
Hi Everyone,

how to access query string value in ASP.Net MVC View, Can anyone give me a solution.

Thank you.


Anupam Mishra

Total Post:135

Points:949
Posted on    March-14-2016 12:30 AM

Hi Sachin,

This is not a good pattern 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. 
For accessing query string to the controller to view then you can set that value to a property in your ViewBag. The ViewBag property can then be read in from your view.You can access Request variable in your view.

In Controller: 

ViewBag.Val = Request.QueryString["Value"];

 In View:


@if(ViewBag.Val == "......"){ ... }

Don't want to miss updates? Please click the below button!

Follow MindStick