开发者

MVC3 Razor view not coping with jQuery CDN fallback script

开发者 https://www.devze.com 2023-04-08 19:07 出处:网络
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 o

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>
  开发者_JS百科  <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?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号