Reputation: 185
I created an MVC5 project where I originally had my resource files in the root of the project. In my views I referenced "Resource.name", for example:
@Html.ActionLink(Resource.CreateButtonText, "Create")
I then decided to move my resource files to a folder called "Resources". My views then showed an error:
The name 'Resource' does not exist in the current context
How do I get rid of this error?
Upvotes: 1
Views: 1170
Reputation: 21548
Almost certainly what has happened here is that the Visual Studio designer has modified the namespace in the resource class to match the folder name.
Try changing:
@Html.ActionLink(Resource.CreateButtonText, "Create")
to:
@Html.ActionLink(Resources.Resource.CreateButtonText, "Create")
or add a using
directive to your view:
@using Resources
Alternatively, if Resource
is a .resx file, right click on the .resx file in Visual Studio and click Properties, and edit the namespace.
Upvotes: 1
Reputation: 185
I found that a using statement can also be done in a view :
@using Resources
where Resources is the namespace configured in the properties of the resource-files (item "Custom Tool Namespace" in VS2017)
Upvotes: 0