Friday, April 11, 2014

App_Code classes not available in Asp.Net Mvc 4 with Microsoft Visual Studio 2012

As in the last few weeks I have started to learn Asp.Net MVC 4 I found few issues. I want to tell you about one pretty awkward.

Just for you to know I have created a project "ASP.NET MVC 4 Web Application" and then as project template I've chosen "Internet Application".


Now: as I wanted to add some of my helper classes and other utilities I created a "App_Code" folder.


Later as I said, I added few classes in that folder. Then I was surprised for I could not use those classes from Controller's folder.
I've tried to change namespace,changing from  MyDemoProject.App_Code to just MyDemoProject. No success :)

So as App_Code classes were not available(accessible) I've searched a little around and I found this solution: you have to go at Properties section of the file and then for Build Action change from Content to Compile. That is it ;)


Of course, you have to bring in the namespace MyDemoProject or MyDemoProject.App_Code as it fits your scenario.

Hope it helped you, too.

6 comments:

  1. Thanks! ran into the same issue today and couldn't figure out why mynamespaces inside App_Code weren't being recognized. This worked.

    ReplyDelete
  2. Thanks a ton. You saved my time and this helped a lot. Thanks a lotttttt. otherwise i was of an impression that my concepts are probably not clear rnough to resolved this issue .

    ReplyDelete
  3. In visual studio 2012 I don't have the option to set build action..what should I do??

    ReplyDelete