I use ASP.NET Internationalization from Code52 at http://code52.org/aspnet-internationalization/ which uses (language) resource files.
From my controller I reference the string I want like this
ViewBag.Message = Language.Index_Title;
Is it possible to reference the values directly in the (razor) view?
Something like this: @Resources.Language.Index_Title;
The namespace for Razor Engine is System. The Razor file extension is "cshtml" for the C# language. By default, Razor View Engine encodes html tags or scripts before it's being rendered to view that avoids Cross-Site Scripting attacks.
Razor is a markup syntax for embedding . NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.
In your web.config you have the "Pages" section... there you need to add your Resource namespace... that way you don't need to declare it in every page using "using".
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Your.Resources.Namespace" /> <!--ADD THIS LINE-->
</namespaces>
</pages>
Then, assuming your resource file is called "Language", in your Razor view you use:
@Language.Index_Title
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