ASP. MVC4 @style. Render

Source: Internet
Author: User
Tags xpath

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

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.