web.config 引用

<configuration>

 <system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
            <add namespace="xEasyApp.Core.Extensions"/> //添加引用空间
        </namespaces>
    </pages>
  </system.web.webPages.razor>

</configuration>

htmlHelper 扩展定义

namespace xEasyApp.Core.Extensions
{
    public static class HtmlHelperExtension
    {
        public static MvcHtmlString Css(this HtmlHelper html, Theme theme, params string[] cssfilename)
        {
            if (cssfilename != null)
            {
                string folderpath = "~/Themes/" + theme;
                string csslink = "<link href=\"{0}\" rel=\"Stylesheet\" type=\"text/css\" />";
                StringBuilder sb = new StringBuilder();
                foreach (string filename in cssfilename)
                {
                    sb.AppendFormat(csslink, UrlHelper.GenerateContentUrl(folderpath+"/"+filename+".css", html.ViewContext.HttpContext));
                }

                return MvcHtmlString.Create(sb.ToString());
            }
            return MvcHtmlString.Empty;
 
        }
        public static MvcHtmlString Css(this HtmlHelper html, params string[] cssfilename)
        {
            return html.Css(Theme.Default, cssfilename);
        }
        public static MvcHtmlString Js(this HtmlHelper html, params string[] jsKeys)
        {
            if (jsKeys != null)
            {               
                string jslink = "<script src='{0}' type='text/javascript'></script>";
                StringBuilder sb = new StringBuilder();
                foreach (string key in jsKeys)
                {
                    var jsurl =JsConfig.GetJsUrl(key,html.ViewContext.HttpContext);
                    if(string.IsNullOrEmpty(jsurl))
                        continue;
                    sb.AppendFormat(jslink, UrlHelper.GenerateContentUrl(jsurl, html.ViewContext.HttpContext));
                }
                return MvcHtmlString.Create(sb.ToString());
            }
            return MvcHtmlString.Empty;

        }

}

}

相关文章:

  • 2021-12-16
  • 2021-07-15
  • 2021-07-10
  • 2022-02-02
  • 2022-01-12
  • 2021-08-01
  • 2021-06-15
  • 2021-06-21
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2021-08-07
  • 2022-02-16
  • 2022-03-04
  • 2021-05-18
相关资源
相似解决方案