MVC3 Razor 视图无法处理 jQuery CDN 后备脚本

发布于 2024-12-06 12:15:17 字数 975 浏览 1 评论 0原文

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

I'm looking to implement loading jQuery from the Google Content Delivery Network. The issue I'm having is that the recommended script from HTML5 Boilerplate is causing the Razor view to lose sight of it's closing curly bracket.

I've tracked it down to the last script line, in the code below. The IDE seems convinced that it doesn't have a closing tag (unsure if it's VS2010, or Resharper reporting it).

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

And running it gives an error about the closing bracket:

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.`

Suggestions as to how to modify the script to suit Razor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

今天小雨转甜 2024-12-13 12:15:17
@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>
}
@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>
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文