Visual Studio confused by server code inside javascript

Posted by Felix on Stack Overflow See other posts from Stack Overflow or by Felix
Published on 2010-06-06T07:36:07Z Indexed on 2010/06/06 7:42 UTC
Read the original article Hit count: 229

I ran into an annoying problem: the following code gives a warning in Visual Studio.

<script type="text/javascript">
var x = <%: ViewData["param"] %>;
</script>

The warning is "Expected expression". Visual Studion gets confused, and all the javascript code after that is giving tons of warnings. Granted, it's all warnings, and it works perfectly fine in runtime - but it is very easy to miss real warnings among dozen of false positives.

It was working the same way in VS2008, and it wasn't fixed in VS2010. Does anybody know if there is a workaround, or a patch?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about JavaScript