MVC3 Razor视图没有应对jQuery CDN后备脚本

时间:2011-09-25 09:40:26

标签: jquery razor cdn google-cdn

我正在寻求从Google Content Delivery Network实施加载jQuery。我遇到的问题是来自HTML5 Boilerplate的推荐脚本导致Razor视图忽略了它的大括号。

我已将其跟踪到最后一个脚本行,在下面的代码中。 IDE似乎确信它没有结束标记(不确定它是VS2010,还是Resharper报告它)。

在视图中:

@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的建议?

1 个答案:

答案 0 :(得分:5)

@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>
}