I am going through the process of converting my site to use ASP.NET MVC 3 with the new razor view engine. I use many extension methods that I have added to the HtmlHelper. I store all these helpers in the following namespace “DevDave.Infrastructure.Helpers”.
In MVC 2 I added the namespace “DevDave.Infrastructure.Helpers” to the web.config file in the root of my MVC project like so:
This allowed me to use my custom helpers in all of my pages. So naturally I figured that the same thing would work for the MVC 3 application. As it turns out it doesn’t, I get this stupid error instead:
As you can see it can’t seem to find my extension method “MainMenu”. Now I did figure out that you could just add a using statement to the top of each page like this:
Well I don’t want to have to put this in every view so then I tried to add the using statement into the _ViewStart file in the root of the views folder. Like so:
This did not work either something about having a using statement inside a code nugget. So I moved it to its own line like so:
This still did not work.
To fix this I had to add the name space to the web.config inside of the views folder instead. Like so:
This fixed the problem.