Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access global resources in a view using asp.net mvc razor

Tags:

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")  
like image 951
FiveTools Avatar asked Jul 09 '12 16:07

FiveTools


People also ask

Does ASP.NET MVC use razor?

Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML. It's just that ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML.

What is MVC Razor view?

Razor is a templating engine and ASP.NET MVC has implemented a view engine which allows us to use Razor inside of an MVC application to produce HTML. However, Razor does not have any ties with ASP.NET MVC. Now, Razor Syntax is compact which minimizes the characters to be used, however it is also easy to learn.


2 Answers

Try this,

@Resources.General.Hello 

syntax: Resources.[ResourceName].[Property]

like image 156
VJAI Avatar answered Sep 17 '22 17:09

VJAI


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.

like image 37
Arun Prasad E S Avatar answered Sep 21 '22 17:09

Arun Prasad E S