3

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?

1 Answer 1

5

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

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Marking the resources as public was the key! Thank you for pointing me in the right direction!
@womp Done! Meant to do that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.