Note that there are some explanatory texts on larger screens.

plurals
  1. POUpgrade from .net 4 to 4.5 breaks Html.Raw call in Javascript
    primarykey
    data
    text
    <p>I have the following code in a c# MVC 3 razor page where I am passing serialized data into a javascript variable for KnockoutJs:</p> <pre><code> @{ var listData = new JavaScriptSerializer().Serialize(Model.ListItems); var pagerData = new JavaScriptSerializer().Serialize(Model.Pager); } // additional code &lt;script type="text/javascript" &gt; var ListData = @(Html.Raw(listData)); // &lt;-- Syntax Error here var PagerData = @(Html.Raw(pagerData)); // &lt;-- Syntax Error here // additional js code &lt;/script&gt; </code></pre> <p>After upgrading to VS 2012, I am getting error squiggles after the javascript semi-colons at the end the Html.Raw lines above. The project complies but VS 2012 displays 'Syntax Error' in the Error List for each line. Without the semi-colons the javascript also shows a 'Syntax Error'. </p> <p>This code worked without issues in the previous version. Is this a bug in the VS 2012 parser and is there a way to avoid the generated errors?</p> <p><strong>Edit</strong> Anyone else seeing this issue? Below is a simplified version with the same issue isolated in a new page. If you add a semi-colon at the end of the ListData line you get a javascript syntax error, without one it is on the next line. Is this a bug in the javascript compiler between VS2010 and VS2012?</p> <pre><code>@{ var listData = "test"; var pagerData = "test2"; } &lt;script type="text/javascript" &gt; var ListData = @(Html.Raw(listData)) var PagerData = @(Html.Raw(pagerData)) &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload