views:

147

answers:

1

I am trying to put all of my strings into the resource file, something I do for all my Windows and Web Forms applications.

Works great when it comes to changes string values for labels and/or localizing the application.

I tried adding the string values to my Web MVC project, but cannot seem to access the Resource file from the inline code in the view.

Is this possible? Is there a better way?

+4  A: 

Where is your resource file? There are a couple things you have to do.

  1. You have to set the custom tool on the resource file to be "PublicResXFileCodeGenerator", rather than just "ResXFileCodeGenerator". This makes the resource class that it generates a public class, rather than an internal class.

  2. Make sure that you are importing the namespace into your View. For example, if you're using the Properties folder to store your resx files, do

    <%@ Import Namespace="MvcApplication1.Properties" %>

Even then, you can't reference it by "Properties.Resource1.MyString"... you have to either use just "Resource1.MyString", or "MvcApplication1.Properties.Resource1.MyString".

Hope that helps.

womp
Marking the resources as public was the key! Thank you for pointing me in the right direction!
mattruma
No problem. Feel free to upvote it too ;)
womp
@womp Done! Meant to do that!
mattruma