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);
- }
- }
mvc 中关于资源文件的扩展的更多相关文章
- 解决asp.net mvc中*.resx资源文件访问报错
个人笔记 问题重现 在asp.net mvc中,使用资源文件会出现一个问题,例如: 紧接着我进入视图界面,输入下面代码: <a href="javascript:void(0);&qu ...
- Spring MVC 处理静态资源文件
摘要: 三个方案: 1.方案一:激活Tomcat的defaultServlet来处理静态文件 2.方案二: 在spring3.0.4以后版本提供了mvc:resources (需要配置annotati ...
- 【解惑】深入jar包:从jar包中读取资源文件
[解惑]深入jar包:从jar包中读取资源文件 http://hxraid.iteye.com/blog/483115 TransferData组件的spring配置文件路径:/D:/develop/ ...
- java 从jar包中读取资源文件
在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...
- html 页面视图中的资源文件(css/js/image)的路径问题。
说到html 页面视图中的资源文件的路径引用问题,这个问题以前一直没去弄明白.今天,我将公司新开发的一个项目完全移植到我本地搭建的php 环境中来,遇到了这个问题,想了一下,然后也不是很困难的就把它给 ...
- (转)java 从jar包中读取资源文件
(转)java 从jar包中读取资源文件 博客分类: java 源自:http://blog.csdn.net/b_h_l/article/details/7767829 在代码中读取一些资源文件 ...
- java基础知识3--如何获取资源文件(Java中获取资源文件的url)
java开发中,常见的resource文件有:.xml,.properties,.txt文件等,后台开发中经常用到读取资源文件,处理业务逻辑,然后返回结果. 获取资源文件的方法说明getResourc ...
- 2.QT中使用资源文件,程序打包
1 程序中使用资源文件 A 一个QT空项目 B 右击项目,添加新文件 添加后的效果是 C 右击main.prc,选择"添加现有项",找到要使用的资源文件.最终的效果是: ...
- 深入jar包:从jar包中读取资源文件getResourceAsStream
一.背景 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等). 在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不 ...
随机推荐
- Spring学习笔记(2)——Bean的配置
要使应用程序中的Spring容器成功启动,需要以下三个方面的条件都具备: 1.Spring框架的类包都已经放到应用程序的类路径下 2.应用程序为Spring提供完备的Bean配置信息 3.Bean的类 ...
- [转]SQL Relay使用
一.SQL Relay是什么? SQL Relay是一个开源的数据库池连接代理服务器 二.SQL Relay支持哪些数据库? * Oracle * MySQL * mSQL * PostgreSQL ...
- CSS各种定位详解
1.定位的专业解释 (1)语法 position:static|absolute|fixed|relative (2)说明 从上面语法可以看出,定位的方法有很多种,它们分别是静态(static),绝对 ...
- python-selenium之firefox、Chrome、Ie运行
测试脚本是否支持在不同浏览器运行firefox浏览器运行脚本 from selenium import webdriver driver=webdriver.Firefox() driver.get( ...
- HttpContext详解
HttpContext 类:封装有关个别 HTTP 请求的所有 HTTP 特定的信息. 在处理请求执行链的各个阶段中,会有一个对象在各个对象之间进行传递,也即会保存 请求的上下文信息,这个对象就是Ht ...
- [原创]IIS7.5下配置ASP+PHP环境及错误处理(0xc0000135)
IIS7.5下配置ASP+PHP环境及错误处理(0xc0000135) http://user.qzone.qq.com/93701178/blog/1398155812 操作系统更新至Win7或Wi ...
- 支持coclock模式
1. /mediatek/custom/htt82_tb_jb5/cgen/cfgdefault/CFG_GPS_Default.h GPS Coclk: 0xFE (enable) 0xFF (di ...
- android studio fetching android sdk component information
解决办法: 1.找到Android Studio安装目录下的idea.properties文件 2.增加disable.android.first.run=true
- Android之ListView&ViewPager模拟新闻界面
模拟新闻 APP 的界面 1)写 ListView 之前先写布局: 这里有两种 Item 的布局: <?xml version="1.0" encoding="ut ...
- LintCode Sort Colors
For this problem we need to sort the array into three parts namely with three numbers standing for t ...