我希望实现从谷歌内容交付网络加载jQuery。我遇到的问题是,从HTML5样板中推荐的脚本导致Razor视图失去了它的右花括号的视线。
在下面的代码中,我一直跟踪到最后一行脚本。IDE似乎确信它没有结束标记(不确定它是VS2010,还是Resharper报告它)。In the View:
@if ([Decision...])
{
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"> </script>
<script type="text/javascript">(window.jQuery || document.write('<script src="/Scripts/jquery-1.6.3.min.js"></script>')) </script>
}
运行它会给出一个关于右括号的错误:
Parser Error Message: The if block is missing a closing `"}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.`
建议如何修改脚本以适应Razor?
@if ([Decision...])
{
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
@:<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"> </script>
@:<script type="text/javascript">(window.jQuery || document.write('<script src="/Scripts/jquery-1.6.3.min.js"></script>'))</script>
}