标签:
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); } }
标签:
原文地址:http://www.cnblogs.com/xiaoyu369/p/4568965.html