Thursday, November 14, 2013

How to use bundle for Javascript and css in ASP.NET MVC?

1. Define bundle:
    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                        "~/Scripts/jquery-ui-{version}.js"));
 }
     }
2. Register Bundle:
In Global.asax
        protected void Application_Start()
        {
            BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
3. Refer bundle
In Razor view
    @Scripts.Render("~/bundles/jquery")

No comments:

Post a Comment