asp.net-mvc – 自动捆绑/缩小是否已在最终版本的MVC 4中获得?
根据
article I read earlier by Scott Guthrie和
video posted by Mads Kristensen,我应该能够通过替换以下内容在ASP.net MVC 4中自动捆绑/缩小:
<link href="Styles/reset.css" rel="stylesheet" type="text/css" /> <link href="Styles/normalize.css" rel="stylesheet" type="text/css" /> <link href="Styles/styles.css" rel="stylesheet" type="text/css" /> <script src="Scripts/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="Scripts/jquery-validation.min.js" type="text/javascript"></script> 有了这个: <link href="Styles/css" rel="stylesheet" type="text/css" /> <script src="Scripts/js" type="text/javascript"></script> 我尝试过针对.Net 4.0和4.5,但它似乎没有什么区别.我收到404错误,链接和脚本标记从不指向捆绑的资源. 这个功能是否从最终版本中删除了? 我想将此功能用于“主题”. 这就是我最终实现的方式.希望它有意义…… /// <summary> /// Render stylesheets HTML for the given theme. Utilizes System.Web.Optimization for bundling and minification /// </summary> /// <param name="themeName">Name of theme</param> /// <returns>HtmlString containing link elements</returns> public static IHtmlString RenderThemeStyles(string themeName) { IHtmlString retValue = null; // If no theme name is passed,return null if (!themeName.HasValue()) return retValue; var ctxt = HttpContext.Current; string themePath = "~/Themes/" + themeName; string themeKey = themePath + "/css"; if (ctxt.Cache[themeKey] != null) return (IHtmlString)ctxt.Cache[themeKey]; // Check to see if the theme directory exists. Throw error if it does not string themeSysPath = HttpContext.Current.Server.MapPath(themePath); DirectoryInfo themeDir = new DirectoryInfo(themeSysPath); if (!themeDir.Exists) throw new ApplicationException(string.Format("Theme directory "{0}" does not exist",themePath)); // Remove the old bundle if it already exists var old_bundle = BundleTable.Bundles.FirstOrDefault(b => b.Path == themeKey); if (old_bundle != null) BundleTable.Bundles.Remove(old_bundle); if (themeDir.GetFiles("*.css").Length > 0) { // If there are css files,add them to the bundler and save the rendered output to cache Bundle styles = new StyleBundle(themeKey).IncludeDirectory(themePath,"*.css"); BundleTable.Bundles.Add(styles); retValue = Styles.Render(themeKey); ctxt.Cache.Insert(themeKey,retValue,new System.Web.Caching.CacheDependency(themeSysPath)); } else { // If there are no css files,save empty string to cache ctxt.Cache.Insert(themeKey,new HtmlString(string.Empty),new System.Web.Caching.CacheDependency(themeSysPath)); } return retValue; } 解决方法
是的,虽然我找不到RC发行说明,但MVC4 RC版本中删除了此功能.
Rick Anderson在upgrade MVC4 beta to RC的博客文章描述了这个过程: 删除“自动捆绑”引用并使用bundle configs创建/复制BundleConfig.cs,并使用BundleConfig.RegisterBundles(BundleTable.Bundles);从Global.asax调用它. 汉塞尔曼提到了一些关于这个决定的backround info:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-core – 获取具有指定角色的用户
- asp.net-mvc – ASP.net身份在删除外部帐户后停止分发外部C
- ASP.NET的BlogEngine.Net堆栈到WordPress?
- asp.net – 通过GET访问Mvc Web API复杂对象查询
- asp.net-mvc – 获取文件夹中的文件
- 如何在ASP.NET RadioButtonList中的项之间添加空间
- asp.net-mvc – 仅在MVC4 BundleConfig中缩小脚本
- asp.net-mvc – 使用ASP.Net MVC中的模型绑定器更新父/子记
- asp.net-mvc – 在MVC 5应用程序中使用autofac in为SignalR
- asp.net-mvc – Windows Azure上的ASP.NET MVC是生产环境的
- ASP.NET Core中Server.Transfer的替代方案
- wcf-data-services – 为什么我的oData响应没有导
- ASP.NET MVC查看用户控件 – 如何设置ID?
- 如何在ASP.Net 3.5中制作标签,标题和字段标题内容
- asp.net-mvc – 在ASP.NET MVC中定制授权
- asp.net – MVC 4如何为WebGrid设置行ID
- asp.net – 如何接收JSON作为MVC 5操作方法参数
- asp.net-mvc – 使用Ninject注册到自定义成员资格
- asp.net – SQL Server查询从ADO.NET运行速度比S
- asp.net-mvc – ASP.NET MVC.如何创建接受和mult