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")
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.
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.
Try this,
@Resources.General.Hello
syntax: Resources.[ResourceName].[Property]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With