How to Bundle and render scripts in mvc 4 -- asp.net? -


i recenly learnt can bundle scripts js/css better , optimized performance. tried implement mvc project scripts aren't rendering. added bundleconfig class under app_start below.

public class bundleconfig     {         public static void registerbundles(bundlecollection bundles)         {             bundles.add(new scriptbundle("~/content/bundles/js").include(                         "~/content/js/jquery.min.js",                         "~/content/js/bootstrap.min.js",                         "~/content/js/jobwebsite.js",                         "~/content/js/bootstrap-datetimepicker.min.js",                        "~/content/js/bootstrap-filestyle.min.js"                         ));              bundles.add(new stylebundle("~/content/bundles/css").include(                        "~/content/css/style.css",                        "~/content/css/bootstrap.min.css",                       "~/content/css/bootstrap-datetimepicker.min.css",                       "~/content/css/social-buttons.css",                       "~/content/css/font-awesome.min.css"                        ));         }     } 

note: new scriptbundle("viturtual path"). please should virtual path be? created new folders , assigned them virtual path. expecting see files created after bundling yet folder still empty. in global.asx, added line below.

jobwebsite.webui.app_start.bundleconfig.registerbundles(system.web.optimization.bundletable.bundles); 

i try render bundle layoutpage

 @scripts.render("~/content/bundles/cs") 

as have seen nothing rendering. vitual path still empty . please missing ? better tut or explanation appreciated.

you make styles bundles this:

bundles.add(new stylebundle("~/styles")                 .include("~/content/styles/bootstrap.css")                 .include("~/content/styles/site.css")); 

the name ~/styles virtual path.

and scripts bundles this:

bundles.add(new scriptbundle("~/scripts")                 .include("~/scripts/jquery-2.1.3.js")                 .include("~/scripts/jquery.validate.js")                 .include("~/scripts/jquery.validate.unobtrusive.js")                 .include("~/scripts/bootstrap.js")); 

the name ~/scripts again virtual path.

to use these bundles, example, in layout file. following:

for styles:

@styles.render("~/styles") 

for scripts:

@scripts.render("~/scripts") 

in example names can changed so:

bundles.add(new scriptbundle("~/scripts").include(     "~/content/js/jquery.min.js",     "~/content/js/bootstrap.min.js",     "~/content/js/jobwebsite.js",     "~/content/js/bootstrap-datetimepicker.min.js",    "~/content/js/bootstrap-filestyle.min.js"     ));  bundles.add(new stylebundle("~/styles").include(    "~/content/css/style.css",    "~/content/css/bootstrap.min.css",   "~/content/css/bootstrap-datetimepicker.min.css",   "~/content/css/social-buttons.css",   "~/content/css/font-awesome.min.css"    )); 

and can call these bundles showed above. names can long can differentiate them.

but if want keep using names you've selected can call them names following example above. replace virtual path names.

note: not need change global.asax file call bundles. bundleconfig class being registered in global.asax @ line says: bundleconfig.registerbundles(bundletable.bundles);. if had empty application line want add application_start() method in global.asax


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -