1. namespace System.Web.Mvc
  2. {
  3. /// <summary>
  4. /// 扩展HtmlHelper
  5. /// </summary>
  6. public static class HtmlHelperExtension
  7. {
  8. public static HtmlString Lang(this HtmlHelper hepler, string resourceFile, string resourceKey)
  9. {
  10. string value = HttpContext.GetGlobalResourceObject(resourceFile, resourceKey).ToString();
  11. //string str = Resources.
  12. return new HtmlString(value);
  13. }
  14. }
  15. }

  

  1.    /// <summary>
  2. /// App_Global and App_Local Resource Provider.
  3. /// </summary>
  4. public interface IResourceProvider
  5. {
  6. /// <summary>
  7. /// To get the Global Resources from a file on the basis of provided key
  8. /// </summary>
  9. /// <typeparam name="T">Value Type</typeparam>
  10. /// <param name="resourceFile">Class Name</param>
  11. /// <param name="resourceKey">Key Name</param>
  12. /// <returns></returns>
  13. T GetGlobalResoceValue<T>(string resourceFile, string resourceKey);
  14.  
  15. /// <summary>
  16. /// To get the Local Resources from a file on the basis of provided key
  17. /// </summary>
  18. /// <typeparam name="T">Value Type</typeparam>
  19. /// <param name="resourceFile">Class Name</param>
  20. /// <param name="resourceKey">Key Name</param>
  21. /// <returns></returns>
  22. T GetLocalResoceValue<T>(string resourceFile, string resourceKey);
  23. }

  

  1.    public class ResourceProvider : IResourceProvider
  2. {
  3. /// <summary>
  4. /// Get the Global Resource Values from the App_Global_Resources
  5. /// </summary>
  6. /// <typeparam name="T">Return Type</typeparam>
  7. /// <param name="resourceFile">File Name</param>
  8. /// <param name="resourceKey"> Key Name</param>
  9. /// <returns></returns>
  10. public T GetGlobalResoceValue<T>(string resourceFile, string resourceKey)
  11. {
  12. return (T)HttpContext.GetGlobalResourceObject(resourceFile, resourceKey);
  13. }
  14.  
  15. /// <summary>
  16. /// Get the Local Resources
  17. /// </summary>
  18. /// <typeparam name="T">Return Type</typeparam>
  19. /// <param name="resourceFile"></param>
  20. /// <param name="resourceKey"></param>
  21. /// <returns></returns>
  22. public T GetLocalResoceValue<T>(string resourceFile, string resourceKey)
  23. {
  24. return (T)HttpContext.GetLocalResourceObject(resourceFile, resourceKey);
  25. }
  26. }

  

mvc 中关于资源文件的扩展的更多相关文章

  1. 解决asp.net mvc中*.resx资源文件访问报错

    个人笔记 问题重现 在asp.net mvc中,使用资源文件会出现一个问题,例如: 紧接着我进入视图界面,输入下面代码: <a href="javascript:void(0);&qu ...

  2. Spring MVC 处理静态资源文件

    摘要: 三个方案: 1.方案一:激活Tomcat的defaultServlet来处理静态文件 2.方案二: 在spring3.0.4以后版本提供了mvc:resources (需要配置annotati ...

  3. 【解惑】深入jar包:从jar包中读取资源文件

    [解惑]深入jar包:从jar包中读取资源文件 http://hxraid.iteye.com/blog/483115 TransferData组件的spring配置文件路径:/D:/develop/ ...

  4. java 从jar包中读取资源文件

    在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...

  5. html 页面视图中的资源文件(css/js/image)的路径问题。

    说到html 页面视图中的资源文件的路径引用问题,这个问题以前一直没去弄明白.今天,我将公司新开发的一个项目完全移植到我本地搭建的php 环境中来,遇到了这个问题,想了一下,然后也不是很困难的就把它给 ...

  6. (转)java 从jar包中读取资源文件

    (转)java 从jar包中读取资源文件 博客分类: java   源自:http://blog.csdn.net/b_h_l/article/details/7767829 在代码中读取一些资源文件 ...

  7. java基础知识3--如何获取资源文件(Java中获取资源文件的url)

    java开发中,常见的resource文件有:.xml,.properties,.txt文件等,后台开发中经常用到读取资源文件,处理业务逻辑,然后返回结果. 获取资源文件的方法说明getResourc ...

  8. 2.QT中使用资源文件,程序打包

     1 程序中使用资源文件 A  一个QT空项目 B  右击项目,添加新文件 添加后的效果是 C  右击main.prc,选择"添加现有项",找到要使用的资源文件.最终的效果是: ...

  9. 深入jar包:从jar包中读取资源文件getResourceAsStream

    一.背景 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等). 在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不 ...

随机推荐

  1. Spring学习笔记(2)——Bean的配置

    要使应用程序中的Spring容器成功启动,需要以下三个方面的条件都具备: 1.Spring框架的类包都已经放到应用程序的类路径下 2.应用程序为Spring提供完备的Bean配置信息 3.Bean的类 ...

  2. [转]SQL Relay使用

    一.SQL Relay是什么? SQL Relay是一个开源的数据库池连接代理服务器 二.SQL Relay支持哪些数据库? * Oracle * MySQL * mSQL * PostgreSQL ...

  3. CSS各种定位详解

    1.定位的专业解释 (1)语法 position:static|absolute|fixed|relative (2)说明 从上面语法可以看出,定位的方法有很多种,它们分别是静态(static),绝对 ...

  4. python-selenium之firefox、Chrome、Ie运行

    测试脚本是否支持在不同浏览器运行firefox浏览器运行脚本 from selenium import webdriver driver=webdriver.Firefox() driver.get( ...

  5. HttpContext详解

    HttpContext 类:封装有关个别 HTTP 请求的所有 HTTP 特定的信息. 在处理请求执行链的各个阶段中,会有一个对象在各个对象之间进行传递,也即会保存 请求的上下文信息,这个对象就是Ht ...

  6. [原创]IIS7.5下配置ASP+PHP环境及错误处理(0xc0000135)

    IIS7.5下配置ASP+PHP环境及错误处理(0xc0000135) http://user.qzone.qq.com/93701178/blog/1398155812 操作系统更新至Win7或Wi ...

  7. 支持coclock模式

    1. /mediatek/custom/htt82_tb_jb5/cgen/cfgdefault/CFG_GPS_Default.h GPS Coclk: 0xFE (enable) 0xFF (di ...

  8. android studio fetching android sdk component information

    解决办法: 1.找到Android Studio安装目录下的idea.properties文件 2.增加disable.android.first.run=true

  9. Android之ListView&ViewPager模拟新闻界面

    模拟新闻 APP 的界面 1)写 ListView 之前先写布局: 这里有两种 Item 的布局: <?xml version="1.0" encoding="ut ...

  10. LintCode Sort Colors

    For this problem we need to sort the array into three parts namely with three numbers standing for t ...