Search code examples
enumsasp.net-mvc-5.net-4.8

Include ENUM in a new ASP.NET MVC project


I've created a new ASP.NET MVC project running on .NET 4.8. I've added classes, controllers, model, interfaces... and it builds properly.

Now I need to create an enum but I'm missing something here. I've created an App_Code folder at the root of the project, added Enum.cs then I created a new namespace as shown here:

namespace ContosoSystem.App_Code
{
    public enum ExpireDate
    {
        SampleExpire = 30,
    }
}

In the controller, I can't apply using ContosoSystem.App_Code nor using ContosoSystem. If I do this, I get this error:

The type or namespace name 'App_Code' does not exist in the namespace 'ContosoSystem' (are you missing an assembly reference?)

At the top left, there is this field mentioning 4_App_Code (see print below). It was supposed to be my project there, but I can't switch to my project as mentioned at the tooltip. So, it seems that Enum.cs is somewhere out of my project.

tool tip at the top left field


Solution

  • I closed this issue by creating an 'Enum.cs' file in the 'Utils' folder, organized and named as shown below:

    namespace ContosoSystem.Enum
    {
        //Sample
        public enum sampleData
        {
            setting = 10,
        }
    }
    

    This solution has been working for the past two months. I didn't understand why I couldn't use App_Code as I had originally planned.