码迷,mamicode.com
首页 > Web开发 > 详细

mvc 中关于资源文件的扩展

时间:2015-06-11 16:08:00      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

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

  

mvc 中关于资源文件的扩展

标签:

原文地址:http://www.cnblogs.com/xiaoyu369/p/4568965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!