Reputation: 21430
I have seen many questions and answers about this; but none of the answers seem to give me a direction here.
The following code works fine when I specify the virtual path as an address to a physical file:
bundles.Add(new Bundle("~/Modules/SIRVA.Connect.Intake.SAP/Content/style.css")
.Include("~/Modules/Intake/Content/Style.css"));
However, if I specify a virtual path that does not exist in the file system (like so...):
bundles.Add(new Bundle("~/content/intake.css")
.Include("~/Modules/Intake/Content/Style.css"));
... MVC will render the the style but when you click on the href it displays, "Page not found," and the styles don't work (because they aren't there).
<link href="/content/intake.css" rel="stylesheet"/>
MVC's own examples appear to point to a non-existent physical location as the virtual path, but it works fine when they do it!
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"
));
Can anyone tell me why I have to set the virtual path of the Bundle()
constructor to a physical file location?
Upvotes: 2
Views: 6560
Reputation: 96
The path isn't supposed to be a physical file location. Can you try and specify a directory instead of a specific file type? Like this (using StyleBundle because I get the idea that you're wanting to create a css bundle):
bundles.Add(new StyleBundle("~/bundles/css")
.Include("~/Modules/Intake/Content/Style.css"));
This will allow the application to make a query string when in production for version control purposes in a production environment (if your bundles are enabled to minimize and compress).
<link rel="stylesheet" href="/bundles/css?v=f-rOZpG8nqcdBI9IS1kiTRlij7Eim7N9U1_RJYwd4_w1"></link>
I believe that using the physical path for a file in bundle works in a limited way, like it won't allow you to add more content there because it's already in use. I haven't really used it in that way, so I don't know what the exact result is.
Edit (Just in case):
You will also need to render it properly in your view. Here's an example (razor view):
@Styles.Render("~/bundles/css")
Upvotes: 3