Пример #1
0
        /// <summary>
        /// CSS脚本资源分组绑定
        /// </summary>
        /// <param name="name">CSS脚本资源绑定名称</param>
        /// <param name="groupName">分组名称</param>
        /// <param name="styles">CSS脚本路径数组 如果为空就绑定分组,如果有知道资源就重新生成资源绑定</param>
        public static void BundlesGroup(string name, string groupName, params string[] styles)
        {
            if (BundleStyles.ContainsKey(name))
            {
                return;
            }
            //获取绑定分组对象
            Bundles gb = null;

            if (BundleStyles.ContainsKey(groupName))
            {
                gb = BundleStyles[groupName];
            }

            if (styles.Count() == 0)
            {
                //未设置其他资源
                if (gb != null)
                {
                    BundleStyles.Add(name, gb);
                }
            }
            else
            {
                //重新生成资源绑定
                if (gb != null)
                {
                    styles = gb.item.Concat(styles).ToArray();
                }
                BundlesAdd(name, styles);
            }
        }
Пример #2
0
        public static IHtmlString Render()
        {
            RequestContext filterContext = HttpContext.Current.Request.RequestContext;
            string         controller    = filterContext.RouteData.Values["controller"].ToString();
            string         action        = filterContext.RouteData.Values["action"].ToString();
            object         area          = filterContext.RouteData.Values["area"];
            string         name          = string.Format("{0}/{1}/{2}", area, controller, action);

            //获取页面定位
            if (!BundleStyles.ContainsKey(name))
            {
                name = BasisName;
            }
            Bundles     b    = BundleStyles[name];
            IHtmlString html = Styles.Render(b.virtualPath);

            return(html);
        }
Пример #3
0
 /// <summary>
 /// CSS脚本资源绑定添加
 /// </summary>
 /// <param name="name">CSS脚本资源绑定名称</param>
 /// <param name="styles">CSS脚本路径数组</param>
 public static void BundlesAdd(string name, params string[] styles)
 {
     if (!BundleStyles.ContainsKey(name))
     {
         string virtualPath = "~/" + Md5.HalfEncryptHexString(name + "/Style");
         BundleTable.Bundles.Add(new StyleBundle(virtualPath).Include(styles));
         Bundles b = new Bundles()
         {
             item        = styles,
             name        = name,
             virtualPath = virtualPath
         };
         if (BundleStyles.Count == 0 && string.IsNullOrEmpty(BasisName))
         {
             BasisName = name;
         }
         BundleStyles.Add(name, b);
     }
 }
        protected virtual void AddPageStyles()
        {
            BundleStyles styles = new BundleStyles(Request.Url.AbsolutePath);

            AddHTMLToHeader(styles.GenerateStyleList());
        }