----------------------------------------------javascript
说明:此篇为当前系列的最后一篇,关于面向移动设备、WEB API 等内容暂时不学。在后面将开发实战项目。css
----------------------------------------------html
1、脚本和样式捆绑包java
位置 :/App_Start/BundleConfig.csjquery
命名空间:System.Web.Optimizationweb
RegisterBundles静态方法会在应用程序第一次启动时,经过Global.asax中Application_Start方法调用ajax
BundleConfig.RegisterBundles(BundleTable.Bundles)安全
建立新的捆绑包时,就是建立StyleBundle或ScriptBundle类的实例,经过构造器参数引用捆绑包路径。框架
为了防止冲突,最安全的方式是以~/bundles或~/Content做为起始路径。ui
定制捆绑包的配置:
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/*.css")); bundles.Add(new ScriptBundle("~/bundles/clientfeaturesscripts").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery.validate.js", "~/Scripts/jquery.validate.unobtrusive.js", "~/Scripts/jquery.unobtrusive-ajax.js" ));
提示:web.config中complilation,true表示常规版,false表示压缩版
注 :MVC 框架处理捆绑包中的{version}时,会智能忽略 IntelliSense文件,且确保Scripts文件夹中只有一种版本的JQuery。
运用捆绑包:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>@ViewBag.Title</title> @Styles.Render("~/Content/css") </head> <body> @RenderBody() @Scripts.Render("~/bundles/clientfeaturesscripts")
@RenderSection("scripts", required: false) </body> </html>
使用Scripts小节:
@section scripts { <script src="~/Scripts/Home/MakeBooking.js" type="text/javascript"></script> }
源代码:http://yunpan.cn/ccbVkY7qzC7ID 访问密码 077a