1

Here is my code:

<text>
    <script type="text/javascript">    
    @foreach (var script in Model.Content.StartupScripts)
    {
        @script
    }    
    </script>
</text>

@script contains a javascript script, but this gets rendered by razor as:

  <script type="text/javascript">    
    {
            {
                var instanceId = &#39;blah&#39;;
                new RequestQueue(&#39; blah
       // etc

So...it looks like the tag is not applying to the @script variable because single quotes are being replaced with &#39;. What am I doing wrong?

Thanks!

2
  • 2
    you need to insert the raw text, MVC is trying to protect you from inserting rogue text that is trying to be script / html Commented Jul 10, 2012 at 3:59
  • ie, its escaping all the text being inserted :) Commented Jul 10, 2012 at 3:59

1 Answer 1

2

Since MVC is automatically encoding all output, you need to force it to display raw text. You can do that with @Html.Raw(script) HTML helper.

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.