问题
How to include style sheets and js files inthe view of Orchard cms, Failed to load resource: the server responded with a status of 404 (Not Found)
回答1:
Create a ResourceManifest.cs file in your Theme or Module.
using Orchard.UI.Resources; namespace MyNameSpace { public class ResourceManifest : IResourceManifestProvider { public void BuildManifests(ResourceManifestBuilder builder) { var manifest = builder.Add(); manifest.DefineStyle("MyScriptName").SetUrl("~/Modules/MyModule/Scripts/scripts.js"); manifest.DefineScript("MyStyleName").SetUrl("~/Themes/MyTheme/Styles/site.css"); } } }
In your view, include the script and style like this:
@{
Style.Require("MyStyleName");
}
@using(Script.Foot()) {
Script.Require("MyScriptName");
}
You can also use Script.Head() to put the .js include in the <head>
tag.
回答2:
You may also use Script.Include
and Style.Include
if you don't want to create a manifest but want to reference the files directly but still eliminating doubles.
The 404
here is very probably due to your failing to include a web.config
file that allows the serving of the file. You can copy the one from one of the existing script directories.
来源:https://stackoverflow.com/questions/10243345/how-to-include-style-sheets-and-js-files-inthe-view-of-orchard-cms