无法在ASP.NET MVC项目中加载捆绑的css

时间:2015-03-30 14:11:51

标签: css asp.net asp.net-mvc-4 mono monodevelop

我在使用最新mono的Linux机器上使用MonoDevelop 5.7创建了一个ASP.NET MVC项目。

我的_Layout.cshtml看起来像这样:

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title>@ViewBag.Title</title>
    @Styles.Render("~/bundle/bootstrap")
</head>
<body>
    <header>
        <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <b><a href="/" class="navbar-brand">EOS</a></b>
                </div>
                <div class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="xml">XML</a></li>
                        <li><a id="toCheckList" href="checklist">Checklist</a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <main role="main">
            <div ng-view class="cont-main"></div>
    </main>

    @RenderBody()

    <script src="Scripts/angular.min.js"></script>
    <script src="Scripts/angular-resource.min.js"></script>
    <script src="Scripts/angular-route.min.js"></script>
</body>
</html>

BundleConfig.cs看起来像这样:

using System;
using System.Web.Optimization;

namespace Angular2 {
    public class BundleConfig {

        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add (new StyleBundle ("~/bundle/bootstrap").IncludeDirectory ("~/Content/css/", "*.css") );


        }
    }
}

我的Global.asax.cs Application_Start()

中也有这一行
BundleConfig.RegisterBundles(BundleTable.Bundles);

现在启动服务器时,页面加载正常但css无法访问。

在源代码中,它包含如下:

<link href="/bundle/bootstrap?v=yW6L0KJ49BsmpuPPWZ1xvWLpXC5uk007PYbOr18eA2k1" rel="stylesheet"/>

但是我的html无法使用它,当我点击链接时我得到了:

System.Web.HttpException
The resource cannot be found.

使用下面的堆栈跟踪:

at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance (System.Web.Routing.RequestContext requestContext, System.Type controllerType) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.DefaultControllerFactory.CreateController (System.Web.Routing.RequestContext requestContext, System.String controllerName) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.ProcessRequestInit (System.Web.HttpContextBase httpContext, IController& controller, IControllerFactory& factory) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.BeginProcessRequest (System.Web.HttpContextBase httpContext, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.BeginProcessRequest (System.Web.HttpContext httpContext, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest (System.Web.HttpContext context, System.AsyncCallback cb, System.Object extraData) [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication+<Pipeline>c__Iterator1.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication.Tick () [0x00000] in <filename unknown>:0 

以下是我的项目图片,以查看css文件的位置:

enter image description here

如何让System.Web.Optimizations正确优化并包含我的资源?

0 个答案:

没有答案