I have the following code on a C # MVC 3 razor page where I pass serialized data to a javascript variable for KnockoutJs:
@{ var listData = new JavaScriptSerializer().Serialize(Model.ListItems); var pagerData = new JavaScriptSerializer().Serialize(Model.Pager); } // additional code <script type="text/javascript" > var ListData = @(Html.Raw(listData)); </script>
After upgrading to VS 2012, I get errors in squidgles after javascript sem-colons at the end of the Html.Raw line above. The project is consistent, but VS 2012 displays a "Syntax error" in the error list for each line. Without half-columns, javascript also shows "Syntax error."
This code worked without problems in the previous version. Is this a bug in the VS 2012 parser and is there a way to avoid the generated errors?
Edit Does anyone else see this problem? Below is a simplified version with the same problem as on the new page. If you add a half-line at the end of the ListData line, you get a javascript syntax error, without which it will be on the next line. Is this a bug in the javascript compiler between VS2010 and VS2012?
@{ var listData = "test"; var pagerData = "test2"; } <script type="text/javascript" > var ListData = @(Html.Raw(listData)) var PagerData = @(Html.Raw(pagerData)) </script>
source share