Accessing ViewData or Request.QueryString() within a script block in ASP.MVC

Aug 14, 2009 at 10:24 AM


Hi everybody,

Sorry if it is not the right place to post.

I am passing a query string with name "RowTobeHighLighted" from my mvc action result.
What I have to do is, I have to get the query string value from that controller action within a script of type text/javascript.

I have tried to use simple Request.Querystring() within javascript. But that is not working. Can anybody please help me. I am in urgent need.
Further, is it possible to get the querystring value from controller action. Or,is it possible to
get the value of viewdata within  <script type="text/javascript"> tag.

Plaease help!!

Thanks in advance.

Aug 14, 2009 at 12:54 PM

My recommendation would be to put the querystring value in the ViewData explicitly in your controllers action. That way, your view can just extract it from <%= ViewData["QSValue"] %> (or put it on a view model object for type safety).