gpt4 book ai didi

asp.net-mvc-4 - Css 和 Js bundle ,IController 异常

转载 作者:行者123 更新时间:2023-12-01 02:19:58 29 4
gpt4 key购买 nike

我正在尝试创建一组 JS 和 CSS 文件。我的文件夹结构是这样的:

  1. ~
    1. Scripts
      1. A
      2. B
      3. C
    2. Content
      1. CSS
        1. ACSS
        2. BCSS
        3. CSS
      2. IMG


我提取了一些帮助表 MVC Central并将此代码添加到我的项目中:
bundles.Add(new ScriptBundle("~/bundles/A/AAA").Include(
"~/Scripts/A/jquery-{version}.js");
bundles.Add(new ScriptBundle("~/bundles/B/BBB").Include(
"~/Scripts/A/jquery-{version}.js");
bundles.Add(new StyleBundle("~/Content/CSS/ACSS").Include("
~/Content/CSS/ACSS/MyCss-*"));

但它返回 404 异常:

System.Web.HttpException (0x80004005): The controller for path '/bundles/A/AAA' was not found or does not implement IController.



编辑:我已在 Global.asax 中注册了我的 bundle 文件。所以至少我没有犯小学生的错误。
BundleConfig.RegisterBundles(BundleTable.Bundles);

我做错了什么导致这个错误?

最佳答案

我遇到了类似的问题,最后似乎从未调用 System.Web.Optimization.PreApplicationStartCode.Start 方法,因此包的路径仍然由通常的 MVC 路由处理。

我的解决方法是在站点的 Global.asax.cs 文件的 Application_Start 方法中手动调用它:

protected void Application_Start(object sender, EventArgs e)
{
//other code startup code here

System.Web.Optimization.PreApplicationStartCode.Start();
}

这样,对包的传入请求由 System.Web.Optimization.BundleHandler ProcessRequest 方法处理。

要更详细地了解代码在幕后如何工作(或应该这样做...),值得在这里查看: http://beletsky.net/2012/04/new-in-aspnet-mvc4-bundling-and.html

关于asp.net-mvc-4 - Css 和 Js bundle ,IController 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21257182/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com