Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Recently I installed visual studio 2012. I converted my project in the log it seems to be fine, No errors. When I look in the code in the javascript at the end of the sentence he marks the ; red and gives the error: "syntax error". Weirdly of all the line of code still works but I only get this error in VS2012 and not in VS2008. The projects still builds because this is javascript. Any idea why this is marked as an error in VS2012?

<link id="Link1" rel="stylesheet" runat="server" media="screen" href="Styles/jquery-ui.css" />
<!-- load jQuery and tablesorter scripts -->
<script type="text/javascript" src="JS/jquery-1.9.1.js"></script>
<script type="text/javascript" src="JS/jquery-ui.js"></script>
<script type="text/javascript" src="JS/jquery.json-2.2.min.js"></script>
<script type="text/javascript">
        var publicationTableSiteIDs = <%= getJsonSiteIDs() %>;
        var publicationTableCountries = <%= getJsonCountries() %>;


public string getJsonSiteIDs()
        {   //list to javascript for autocorrect on site id's
            return (new JavaScriptSerializer()).Serialize(siteIdsList.Distinct().ToList());
        }

        public string getJsonCountries()
        {   //list to javascript for autocorrect on countries
            return (new JavaScriptSerializer()).Serialize(countryList.Distinct().ToList());
        }
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Visual Studio's editor is trying to parse your interpolated server-side code as Javascript, resulting in a syntax error.

At runtime, the server-side code is properly executed on the server, returning valid Javascript (unless your data has U+2028), so it works fine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.