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); } }

      

  • 相关阅读:
    Java基础50道经典练习题(33)——杨辉三角
    Java基础50道经典练习题(32)——左移右移
    团队第二阶段冲刺04
    团队第二阶段冲刺03
    团队第二阶段冲刺02
    团队第二阶段冲刺01
    团队意见汇总
    各组意见汇总
    团队第一阶段冲刺07
    绩效评估01
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/4568965.html
Copyright © 2011-2022 走看看