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 = 'blah';
new RequestQueue(' blah
// etc
So…it looks like the tag is not applying to the @script variable because single quotes are being replaced with '. What am I doing wrong?
Thanks!
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.