How to include style sheets and js files inthe view of Orchard cms

假装没事ソ 提交于 2019-12-10 00:57:43

问题


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:


  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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!