1

In my scenario, i need to get QueryString value on page load on Partial view in MVC my code is:

<script type="text/javascript" language="javascript">
  $(document).ready(function () {
    var industries = '@Request.QueryString["industries"]';
    alert(industries);
}); 

</script>

When i rendering QueryString value that time it is working fine but in Javascript it's not working.

tereško
  • 58,060
  • 25
  • 98
  • 150
Amit Sharma
  • 1,088
  • 1
  • 19
  • 44
  • 1
    Try [this](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript). Also keep the scripts in the main view as much as you can instead of within partial views. – Siva Gopal Dec 23 '14 at 08:39

1 Answers1

6

Here is a work around:

Make Hidden Feild and put the QS in it, then get the value using jquery selector.

  <input type='hidden' value='@Request.QueryString["industries"]' id='HdnIndustries' />

  <script type="text/javascript" language="javascript">

  $(document).ready(function () {
    var industries = $("#HdnIndustries").val();
    alert(industries);
  }); 

  </script>
user2120121
  • 665
  • 1
  • 6
  • 15