• mvc 中关于资源文件的扩展


    namespace System.Web.Mvc
    {
        /// <summary>
        /// 扩展HtmlHelper
        /// </summary>
        public static class HtmlHelperExtension
        {
            public static HtmlString Lang(this HtmlHelper hepler, string resourceFile, string resourceKey)
            {
                string value = HttpContext.GetGlobalResourceObject(resourceFile, resourceKey).ToString();
                //string str = Resources.
                return new HtmlString(value);
            }
        }
    }
    

      


       /// <summary> /// App_Global and App_Local Resource Provider. /// </summary> public interface IResourceProvider { /// <summary> /// To get the Global Resources from a file on the basis of provided key /// </summary> /// <typeparam name="T">Value Type</typeparam> /// <param name="resourceFile">Class Name</param> /// <param name="resourceKey">Key Name</param> /// <returns></returns> T GetGlobalResoceValue<T>(string resourceFile, string resourceKey); /// <summary> /// To get the Local Resources from a file on the basis of provided key /// </summary> /// <typeparam name="T">Value Type</typeparam> /// <param name="resourceFile">Class Name</param> /// <param name="resourceKey">Key Name</param> /// <returns></returns> T GetLocalResoceValue<T>(string resourceFile, string resourceKey); }

      


       public class ResourceProvider : IResourceProvider { /// <summary> /// Get the Global Resource Values from the App_Global_Resources /// </summary> /// <typeparam name="T">Return Type</typeparam> /// <param name="resourceFile">File Name</param> /// <param name="resourceKey"> Key Name</param> /// <returns></returns> public T GetGlobalResoceValue<T>(string resourceFile, string resourceKey) { return (T)HttpContext.GetGlobalResourceObject(resourceFile, resourceKey); } /// <summary> /// Get the Local Resources /// </summary> /// <typeparam name="T">Return Type</typeparam> /// <param name="resourceFile"></param> /// <param name="resourceKey"></param> /// <returns></returns> public T GetLocalResoceValue<T>(string resourceFile, string resourceKey) { return (T)HttpContext.GetLocalResourceObject(resourceFile, resourceKey); } }

      

  • 相关阅读:
    考研系列一-线性表类(顺序存储)
    因特网协议分层及它们的服务模型
    矩阵归零
    字符编码(续)---Unicode与ANSI字符串转换以及分辨字符编码形式
    奇妙的位运算
    一道面试题Lintcode196-Find the Missing Number
    错误处理
    px 和 em 的区别
    简述同步和异步的区别
    简述一下 src 与 href 的区别
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/4568965.html
Copyright © 2020-2023  润新知