0

I'm starting to move away from having my classes in a folder called App_Code in my MVC4 projects, and moving all my classes into the folder called Models.

Now I've encountered a problem with my old code.

In my cshtml files I used to call my App_Code classes with a @using projectName.App_Code in the beginning of the file. But that doesn't work now.

My question is therefore; How would I call a class in my Model folder from my cshtml files?

Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89

1 Answers1

1

If you have moved your classes (and changed the namespace when you moved them) then you will need to change the @using namespace reference in the cshtml file from the old reference to the new reference.

To help with this, you could change your web project to compile the views to show any references that fail when you perform a build. To do this you will need to change the <MVCBuildViews> setting in the .csproj file to true as mentioned here by Phil Haack.

Additionally, as mentioned here in the answer by Javad_Amiry, you can update the list of namespaces that are used by your views by updating the <namespaces> setting in the the web.config file.

Community
  • 1
  • 1
Dangerous
  • 4,818
  • 3
  • 33
  • 48