Reference: http://www.cnblogs.com/madyina/p/3702314.html
http://blog.csdn.net/zhou44129879/article/details/16818987
Function Description:
1. @Styles. Render ("~/content/css"), @Style. Render ("~/content/css1", "~/content/css2" [,...]) :
Page load specified CSS file
[Email protected] ("~/content/script"), @Scripts. Render ("~/xpath/script1", "~/xpath/script2" [,...]) :
Page load Specify JS file
To add a step:
1. Add BundleConfig.cs under App_start , set the file to be bound
usingsystem.web;usingSystem.Web.Optimization;namespacexxx{ Public classBundleconfig { Public Static voidregisterbundles (bundlecollection bundles)//scarlet Letter part matches the version number {bundles. ADD (NewScriptbundle ("~/bundles/jquery"). Include ("~/scripts/jquery-{version}.js")); Bundles. ADD (NewScriptbundle ("~/bundles/jquery-min"). Include ("~/scripts/jquery-{version}.min.js")); Bundles. ADD (NewScriptbundle ("~/bundles/bootstrap"). Include ("~/scripts/bootstrap-{version}.min.js")); Bundles. ADD (NewScriptbundle ("~/bundles/modernizr"). Include ("~/scripts/modernizr-*")); Bundles. ADD (NewStylebundle ("~/content/css"). Include ("~/content/style.css")); } }}
2.global.asax Configuration Content
Application_Start adding Bundleconfig related content
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.Http;usingSYSTEM.WEB.MVC;usingSystem.Web.Routing;usingsystem.web.optimization;namespacexxx{ Public classMvcApplication:System.Web.HttpApplication {protected voidApplication_Start () {arearegistration.registerallareas (); Webapiconfig.register (globalconfiguration.configuration); Filterconfig.registerglobalfilters (globalfilters.filters); bundletable.enableoptimizations = True;//default is True, in production environment, CSS and JS and other files will be bundled and compressed, development mode does not perform this operation bundleconfig.registerbundles (bundletable.bundles); Routeconfig.registerroutes (routetable.routes); } }}
3. Add content to the page
<Head> <Metahttp-equiv= "Content-type"content= "text/html;charset="UTF=-8 "; Width=device-width,Initial-scale=1.0,Maximum-scale=1.0,user-scalable=no "/> <MetaCharSet= "Utf-8"/> <Metaname= "Viewport"content= "Width=device-width" /> <title>@ViewBag. Title</title>@Styles. Render ("~/cotent/css") @Styles. Render ("~/bundles/modernizr") @Scripts. Render ("~/bundles/jquery") @Scripts. Render ("~/bundles/bootstrap")</Head>
ASP. MVC4 @style. Render