zoukankan      html  css  js  c++  java
  • 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); } }

      

  • 相关阅读:
    【字符串哈希】The 16th UESTC Programming Contest Preliminary F
    【推导】The 16th UESTC Programming Contest Preliminary L
    【推导】zoj3846 GCD Reduce
    【spfa】【动态规划】zoj3847 Collect Chars
    【搜索】【组合数学】zoj3841 Card
    【贪心】【字典树】Gym
    【贪心】【后缀自动机】Gym
    【拉格朗日插值法】【找规律】【高精度】Gym
    【二分】【动态规划】Gym
    【软件开发综合实验】文本压缩软件
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/4568965.html
Copyright © 2011-2022 走看看