1

我正在寻找实现从谷歌内容交付网络加载 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 的建议?

4

1 回答 1

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>
}
于 2011-09-25T09:43:58.463 回答