asp.net全局资源错误“找不到键为“''的资源对象" [英] asp.net global resources error 'The resource object with key '' was not found'

查看:108
本文介绍了asp.net全局资源错误“找不到键为“''的资源对象"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net全局资源来尝试建立一个两种语言的网站,我在名为 en-Us.resx 的全局资源文件中添加了一个简单的资源,该文件包含:

I'm using asp.net global resource to try and implement a two language website, I added a simple resource in the global resource file called en-Us.resx that contains:

Password | Text
Email | Text

然后将其实现到默认页面内的文本框:

then implemented it to a textbox within the default page:

<asp:TextBox runat="server" ID="loginEmail" Text="<%$ Resources:en-US, Email %>" 
                            ></asp:TextBox>

但是当我在 localhost 上运行页面时,会出现此错误:

but when ever I run the page on localhost I get this error:

找不到键为"的资源对象

The resource object with key '' was not found

我正在使用asp.net 4.0,这是什么问题?

I am using asp.net 4.0, what is the problem?

推荐答案

资源文件的格式为ResourceName.culture.resx

The format of resource files are ResourceName.culture.resx

在App_GlobalResources文件夹中创建一个资源文件,名为 Main.resx.这是默认的区域性(即Invariant)

Create a resource file in the App_GlobalResources folder called Main.resx. This is for the default culture ( ie Invariant )

然后创建一个资源文件Main.en-US.resx

Then create a resource file Main.en-US.resx

这是美国文化的所有资源都将居住的地方,依此类推.

This is where all the resources for en-US culture will live, and so on.

Main.resx  
Main.en.resx  
Main.en-US-resx  
Main.en-AU.resx  
Main.fr.resx  
Main.fr-FR.resx  

要从网页上访问此文件,请使用语法

To access this from the webpage use the syntax

<%$ Resources:Main, Email %>

不用担心文化,系统会解决这个问题.它将首先完全匹配(en-US),然后进行完全匹配,以适应父级(en),父级父级(Invariant)的文化.

Don't worry around the culture, the system will work it out. It will exact match first ( en-US ), then work up to that's cultures parent ( en ), parent's parent ( Invariant ).

更改"Main"的名称以适合您的需求

Change the name of "Main" to suit your needs

这篇关于asp.net全局资源错误“找不到键为“''的资源对象"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆