示例#1
0
        /// <summary>
        /// 往页面中写入js文件
        /// </summary>
        /// <param name="htmlHelper">需要扩展对象</param>
        /// <param name="jsFiles">文件路径</param>
        /// <returns></returns>
        public static MvcHtmlString AppendJsFile(this HtmlHelper htmlHelper, params string[] jsFiles)
        {
            string jsFile = "";

            foreach (string file in jsFiles)
            {
                if (jsFile != "")
                {
                    jsFile += ",";
                }
                jsFile += file;
            }
            string jsStr = "";

            if (Config.GetValue("JsCompressorCache") == "true")
            {
                jsStr = cache.Read <string>(jsFile, CacheId.jscss);
            }
            if (string.IsNullOrEmpty(jsStr))
            {
                jsStr = JsCssHelper.ReadJSFile(jsFiles);
                cache.Write <string>(jsFile, jsStr, CacheId.jscss);
            }

            StringBuilder content  = new StringBuilder();
            string        jsFormat = "<script>{0}</script>";

            content.AppendFormat(jsFormat, jsStr);
            return(new MvcHtmlString(content.ToString()));
        }
        /// <summary>
        /// 往页面中写入js文件
        /// </summary>
        /// <param name="htmlHelper">需要扩展对象</param>
        /// <param name="jsFiles">文件路径</param>
        /// <returns></returns>
        public static MvcHtmlString AppendJsFile(this HtmlHelper htmlHelper, params string[] jsFiles)
        {
            StringBuilder content  = new StringBuilder();
            string        jsFormat = "<script>{0}</script>";
            string        jsStr    = JsCssHelper.ReadJSFile(jsFiles);

            content.AppendFormat(jsFormat, jsStr);
            return(new MvcHtmlString(content.ToString()));
        }