I'm at wits' end here.
Steps to reproduce at the bottom
I've created an MVC 4 project, say MyProj.Mvc
, in Visual Studio 2012 Update 3.
I followed the suggestion here to put my GlobalResources.resx
in a Resources
folder under the project, so that it will compile into the DLL. I have looked at the generated code in GlobalResources.resx.cs
, and everything is public. I can access the resources from other .cs
files (e.g. HomeController.cs
) just fine.
I cannot get the MyProj.Mvc
namespace to be in the current context in any view.
For instance, in any Razor view, I can reference a resource like this just fine:
@MyProj.Mvc.Resources.GlobalResources.AppName
However, when I try to do the following:
@Resources.GlobalResources.AppName
I get an error. The Resources
namespace is not found.
I followed the advice here and put the namespace in my ~/Views/Web.config:
<add namespace="MyProj.Mvc" />
And, the view still cannot recognize the Resources
namespace. Rebuilding and/or restarting Visual Studio does not work.
"Ok," I think, "screw it, I'll just put a @using
statement at the top of the page and deal with it later."
@using MyProj.Mvc // put at the top of the page
And, the view still cannot recognize the Resources
namespace.
So please, help. Help! What could I possibly be doing wrong, that putting a @using
statement at the top of the page still doesn't bring the namespace into scope?
Steps to reproduce:
I've been able to reproduce this with brand-new, clean projects. Visual Studio 2012 Update 3, create a new ASP.NET MVC 4 Web Application called MyProj.Mvc
. For the template, I'm mostly concerned with the Internet Application, though I've also reproduced this on my machine with the Empty project; select the Internet Application just to better match what I have. At the top of _Layout.cshtml
, put @using MyProj.Mvc
. Somewhere else on the page, begin typing @Controllers.HomeController
. Note that the auto-complete doesn't even attempt to offer up the Controllers
namespace, let alone the HomeController
.
Now it gets weird:
So, that failed. Here's something, though. Try changing the using
statement to @using MyProj.Mvc.Controllers
. Now, go back and start typing @HomeController
. IT WORKS!