【问题标题】:Uncaught SyntaxError: Unexpected token exception after bundle two CSS file in MVC4未捕获的 SyntaxError:在 MVC4 中捆绑两个 CSS 文件后出现意外的令牌异常
【发布时间】:2013-04-14 15:53:51
【问题描述】:

在我的 MVC4 项目中,我捆绑了两个 css 文件。当浏览渲染这个文件时,我得到了两个异常。

Uncaught SyntaxError: Unexpected token .
Uncaught SyntaxError: Unexpected token {  

我为捆绑我的 CSS 文件编写了这段代码。

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new StyleBundle("~/Content/css")
    .Include("~/Content/css3.css","~/Content/styles.css"));
}

我在我的 _Layout.chshtml 页面中调用它。

<head>
   @Scripts.Render("~/Content/css")
</head>

并获得该异常。

但如果我以这种方式调用这些 CSS 文件,那么一切正常。

<head>
    <link href="~/Content/css3.css" rel="stylesheet" />
    <link href="~/Content/styles.css" rel="stylesheet" />
</head>

这是我的错误的屏幕截图。

【问题讨论】:

    标签: css asp.net-mvc optimization asp.net-mvc-4 bundle


    【解决方案1】:

    这是因为它正在渲染一个&lt;script&gt; 标记。它应该是@Styles.Render 而不是@Scripts.Render。

    【讨论】:

    • 这发生在我调用 @Scripts.Render("~/bundles/custom") 时,我认为 BundleConfig.cs 文件中没有相应的 ScriptBundle 设置。
    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 2016-10-23
    • 2015-08-19
    相关资源
    最近更新 更多