1

我正在尝试通过 NuGet开始使用Cassette 。我在我的应用程序中遇到了问题,所以我回滚并在一个新的空 ASP.NET MVC 3 Web 应用程序中尝试了它。

但是,问题仍然存在。按照文档页面“易于使用”,我根本无法让它工作。这是异常以及一些堆栈:

"Object reference not set to an instance of an object."

[NullReferenceException: Object reference not set to an instance of an object.]
   Cassette.CassetteApplicationContainer.get_Application() +6
   Cassette.Views.Bundles.Reference(String assetPathOrBundlePathOrUrl, String pageLocation) +14
   ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:\Dave\Documents\Visual Studio 2010\Projects\CasetteTest\Views\Shared\_Layout.cshtml:2
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207

我只是按照文档中的两个步骤进行操作,这就是我得到的。我究竟做错了什么?

这是我的_Layout.cshtml文件的样子:

@{
    Bundles.Reference("Scripts/jquery-1.5.1.min.js");
    Bundles.Reference("Scripts/modernizr-1.7.min.js");    
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>

<body>
    @RenderBody()
    @Bundles.RenderScripts();
</body>
</html>
4

2 回答 2

3

我想到了。

I included the Cassette.Views package which does not create a default CassetteConfiguration.cs file that bundles each script and each css file in its own bundle. That's what triggered the NullReferenceException. In order to get it to work, you'll need to add the Cassette.Web package instead. In my defense, the package descriptions in the NuGet gallery are not clear and one is led to believe that the Views package is required for MVC and the other for WebForms.

The next problem was that I referenced the minified '.min.js' scripts which are not picked up by the bundler (it seems).

于 2012-03-26T18:57:45.080 回答
2

无法重现该问题。

4 个简单的步骤让我在不到 30 秒的时间内获得了一个完整的原型:

  1. 在 Visual Studio 中创建一个新的 ASP.NET MVC 3 项目
  2. Install-Package Cassette.Web
  3. Index.cshtml

    @using Cassette.Web
    @{
        Bundles.Reference("~/Scripts/jquery-1.5.1.js");
        Bundles.Reference("~/Scripts/jquery-ui-1.8.11.js");
        Bundles.Reference("~/Content/site.css");
        Layout = null;
    }
    <!DOCTYPE html>
    <html>
    <head>
        <title>Web App</title>
        @Bundles.RenderStylesheets()
    </head>
    <body>
        <div>Hello World</div>
        @Bundles.RenderScripts()
    </body>
    </html>
    
  4. 点击Ctrl+F5运行项目
于 2012-03-26T18:11:39.750 回答