Razor MVC Multi-language 多语言系统的实现的问题
来源:互联网 发布:安易数据恢复免费版 编辑:程序博客网 时间:2024/06/18 06:12
Razor MVC Multi-language 多语言系统的实现的问题
控件,自身支持,例如Telerik
根据控件对Resource文件的名称的要求,建立APP_GlobaResource目录下的文件
在web.config中修改UICulture等信息就完成了某个语言显示的设定
Globalization in MVC 3with Razor
主要
一、 处理Form Request,类似之前的ASP模式,通过Submit然后后台的ActionURL ASP页面接收参数,处理反馈。
基本要求:
1.前台有Form,有Submit,有提交的内容
@{Html.BeginForm("Index","Home");}<table cellpadding="0″cellspacing="0"style="border:0px none white; width:600px;"><tr><tdstyle="width:300px;"> <table cellspacing="0"cellpadding="0"style="border:0px none white; width:300px;"><tr><tdstyle="width:150px;text-align:left;">Language</td><tdstyle="width:150px;text-align:right;"><inputtype="submit"value="Update Language"/>
….
</table>@{Html.EndForm();}
2.后台控制器 Controller
一个Action,对应Form中的Html.BeginForm("Index","Home")
public ActionResult Index(String language) { …}
3.这个过程要理解刷新,或则page_load
二、关于通过代码访问资源的方式:
使用接口(其中的Namespace就来自Customtoolnamespace)
<td style="width:300px;">@HWResources.ServerSide.HelloString</td>
定义方式:(设置很重要)
三、View Access of Local Resource using Html Extension Method
通过HTML help的扩展访问本地资源
Razor与传统的Web Form view引擎不一样,web form允许代码访问资源。这里讲如何通过HTML扩展来调用类似GetLocalResourceObject的方式:
主要是 page.ViewContext.HttpContext.GetLocalResourceObject
提一下使用HTMLHelper的步骤:
1. 创建一个来自html helper的扩展类
2. 注册到Razor viewEngine configuration entry,通过web.config,在
<System.Web.WebPages.Razor>
记住这个是在view\web.config
这个方式总体来说的步骤:
1. 写Extension,第一个参数,以及确认使用LocaresourceObject,就是要来自APP_LocalResources目录
public static string LocalResources(this WebViewPage page, string key) { //如果需要图片资源,不过基本还是string为主 return page.ViewContext.HttpContext.GetLocalResourceObject(page.VirtualPath, key) as string;}
2.Razor view代码
<b>View Access of custom embedded resource using html extension</b></td><td style="width:300px;">@this.LocalResources("String1")</td>
LocalResources(this WebViewPage page=@this, string key= String1)
四、上述代码的简化版,但显然导致过多代码:
<b>View Access of Local Resource using Http Context GetLocalResourceObject ....</b></td><td style="width:300px;">@HttpContext.GetLocalResourceObject("~/Views/Home/Index.cshtml","String1")</td>
参数需要使用当前的View的页面。"~/Views/Home/Index.cshtml"
最后的效果:
- Razor MVC Multi-language 多语言系统的实现的问题
- MVC Razor的使用
- Razor与SPA,关于MVC-View实现的思考
- MVC的Razor视图引擎:RenderBody,…
- 新学MVC和razor的实际用法
- asp.net mvc razor布局页中a标签的href的跳转问题
- Acro Multi-Language多语言元件增加Unicode支持
- 使用Razor+MVC+PartialView实现预览记账凭证的HTML页面
- MVC4 Razor引擎的两个小问题
- MVC razor 中 RenderPartial, RenderAction , Partial , Action 的使用选择
- ASP.NET MVC的Razor引擎:View编译原理
- mvc Razor 视图中找不到 ViewBag的定义
- MVC razor 中 RenderPartial, RenderAction , Partial , Action 的使用选择
- ASP.NET MVC的Razor引擎一:View编译原理
- ASP.NET MVC的Razor引擎二:RazorView、RazorViewEngine
- 《MVC》--用Razor给DropDownListFor绑定最近半年的时间
- ASP.NET MVC Razor 输出没有编码的HTML字符串
- MVC Razor
- C# 中配置文件app.config读取速度测试
- 设计模式一点通之单态模式
- 装jdk1.5在cmd中Java -version 显示jdk1.4.2...
- tar gzip biz2 rar unrar的使用,解压tar.gz文件,运行.sh脚本
- android JavaMail发送邮件(可发送附件)
- Razor MVC Multi-language 多语言系统的实现的问题
- 用了一段时间word office插件,找到了一个类似可用的api说明
- Audinst HUD-mx1 - 初来乍到
- 加速度传感器采集的加速度值有没有必要转换为位移量
- 15 个微型 JavaScript 框架
- com/sun/image/codec/jpeg/ImageFormatException
- Oracle - SQL 优化 -------- > 创建PLUSTRACE角色
- HTTP协议详解
- Linux init.d