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.

1
  • 1
    Try this. Also keep the scripts in the main view as much as you can instead of within partial views. Commented Dec 23, 2014 at 8:39

1 Answer 1

5

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.