MVC ScriptBundle custom sorting ., Mvcscriptbundle

Source: Internet
Author: User

MVC ScriptBundle custom sorting ., Mvcscriptbundle

Today, we found the ScriptBundle @ Scripts of MVC. after the Render () is displayed on the page according to the order I do not know, the consequence is jquery. min. js is listed at the backend (the default jquery in my pile below. min. js in the third place) causes javascript to report errors, so in many cases, it cannot be automatically sorted by the first letter.

The solution is as follows:

First, create a new class:

internal class AsIsBundleOrderer : IBundleOrderer{    public virtual IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)    {        return files;    }}

 

Then bind it as follows:

ScriptBundle mandatoryJs = new ScriptBundle("~/Metronic/mandatoryJs");mandatoryJs.Orderer = new AsIsBundleOrderer();mandatoryJs.Include(        "~/plugins/Metronic/global/plugins/jquery.min.js",        "~/plugins/Metronic/global/plugins/jquery-migrate.min.js",        "~/plugins/Metronic/global/plugins/jquery-ui/jquery-ui.min.js",        "~/plugins/Metronic/global/plugins/bootstrap/js/bootstrap.min.js",        "~/plugins/Metronic/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js",        "~/plugins/Metronic/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js",        "~/plugins/Metronic/global/plugins/jquery.blockui.min.js",        "~/plugins/Metronic/global/plugins/jquery.cokie.min.js",        "~/plugins/Metronic/global/plugins/uniform/jquery.uniform.min.js",        "~/plugins/Metronic/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js"    );bundles.Add(mandatoryJs);

That's all.

Finally, you can simplify the process:

bundles.Add(new ScriptBundle("~/Metronic/mandatoryJs") { Orderer = new AsIsBundleOrderer() }.Include(        "~/plugins/Metronic/global/plugins/jquery.min.js",        "~/plugins/Metronic/global/plugins/jquery-migrate.min.js",        "~/plugins/Metronic/global/plugins/jquery-ui/jquery-ui.min.js",        "~/plugins/Metronic/global/plugins/bootstrap/js/bootstrap.min.js",        "~/plugins/Metronic/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js",        "~/plugins/Metronic/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js",        "~/plugins/Metronic/global/plugins/jquery.blockui.min.js",        "~/plugins/Metronic/global/plugins/jquery.cokie.min.js",        "~/plugins/Metronic/global/plugins/uniform/jquery.uniform.min.js",        "~/plugins/Metronic/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js"    ));

It looks like a start.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.