Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access My.Resources from a razor view

I have a razor .vbhtml view and would like to use string resources normally accessible via My.Resources. Seems like I can only get to My.Computer, My.Log and couple other namespaces from the view, but not My.Resources. I've tried changing access modifier to public and adding @Imports, neither worked.

Thanks

like image 898
radimd Avatar asked Jul 06 '11 21:07

radimd


People also ask

How do I display Cshtml?

Right click the Index. cshtml file and select View in Browser. You can also right click the Index. cshtml file and select View in Page Inspector.

How do I display an image in razor view?

Step 1 - Go to SQL Server Management System and execute the following script. Step 2 - Go to Visual studio and add a new project. Select “Asp.Net MVC 4 Web Application” and give the name for this ,In my case it is “MVCDemoProject. ” -> Select a Project template as Empty and View engine is “Razor”, Then Click OK.


1 Answers

Add a Messages.resx file to your project. In the properties of this file in the solution explorer set Custom Tool = PublicResXFileCodeGenerator. Now inside the view you can directly access resources:

@Imports AppName.My.Resources

<div>@Messages.Foo</div>

And here's a screenshot containing all you need:

enter image description here

like image 138
Darin Dimitrov Avatar answered Sep 20 '22 03:09

Darin Dimitrov