How to access global resources in a view using asp

2019-03-18 03:57发布

Using ASP.NET MVC Razor, I have a resource file in App_GlobalResources named General.resx and General.fr.resx with a name value pairings of "Hello" and "Hello" and "Hello" and "Bonjour".

How do I reference these from my view?

These do not work:

@Html.Resource("General.Hello")
@Html.Resource("GlobalResources.Hello")
@Html.Resource("GlobalResources.General.Hello")
@Html.Resource("GlobalResources, General.Hello") 

3条回答
对你真心纯属浪费
2楼-- · 2019-03-18 04:24

Try this,

@Resources.General.Hello

syntax: Resources.[ResourceName].[Property]

查看更多
Fickle 薄情
3楼-- · 2019-03-18 04:38

To access value from resoure file in view

Add this name space

@using System

Then display the value like this

@ResourceFile.Address  (ResouceFile is the name of the ResouceFile)

This method is used when evironment culture thread is used.

查看更多
Evening l夕情丶
4楼-- · 2019-03-18 04:40

you need to refer to your namespace:

@GeneralResxNamespace.General.Hello

You can do this in an easier way by adding namespace to /Views/Web.config file In section with namespaces add section below:

<add namespace="*YourProjectNamespace*.*ResourcesNamespace*.Resources" />

Then you can use resources without namespace, like in the example:

General.Hello
查看更多
登录 后发表回答