MVC cannot display image using background-url in css - uses bundling

前端 未结 4 526
花落未央
花落未央 2020-12-20 22:07

I have an MVC4 project which has the following structure:

/Content/css/sprites/topbar.css

/Content/images/topbar.png

In the c

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 22:41

    Don't know if anyone else was having this problem. But you CAN use relative paths in your css. The key is registering the bundle with a virtual path to the same folder where your actuall css will reside. This way MVC Will request the bundled css from a handler in that path.

    Try changing your bundle registration to:

    bundles.Add(new StyleBundle("~/Content/css/sprites/topbar")
                  .Include("~/Content/css/sprites/topbar.css")
                );
    

    Then in your view @Script.Render("/Content/css/sprites/topbar")

    Mvc will request your complied css bundle from /Content/css/sprites/topbar?{some-crazy-token-thing}

提交回复
热议问题