无法在VS2012中使用捆绑/缩小功能

时间:2012-06-07 20:22:55

标签: visual-studio

我正在使用Visual Studio 2012 RC

我创建了一个ASP.NET 4 Web应用程序/ Internet应用程序

在视图中我有这段代码:

<script type="text/javascript">
  $(function () {
    alert("Test");
  });
</script>

尽管长时间搜索,但我无法使用Bundling / Minification。在_Layout.cshtml中,我有以下内容。我没有做其他事情。有人可以告诉我我需要做什么吗?非常感谢。

  @Styles.Render("~/Content/themes/base/css", "~/Content/css")
  @Scripts.Render("~/bundles/modernizr")

  @*This line Does Not Work*@
  @Scripts.Render("~/Scripts/js")

  @*This Line Does Work*@ 
  <script type="text/javascript" src="~/Scripts/jquery-1.7.2.js"></script>

1 个答案:

答案 0 :(得分:4)

首先创建脚本包,然后添加您想要的任何脚本。

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-1.*",
        "~/Scripts/jquery-ui-1.8.20.js"));
}

然后在你的页面中使用@ Scripts.Render:

@Scripts.Render("~/bundles/jquery");

请注意,我在上面的ScriptBundle中指定的路径与我在Scripts.Render中使用的路径相同。

请遵循这篇文章http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

相关问题