Last post Jun 27, 2017 01:00 PM by Mikesdotnetting
Jun 27, 2017 06:19 AM|jose.mld14|LINK
There is no existing namespace declaration. The problem that I am now facing is that I don't know the namespace associated in this project. And even if I am going to create a namespace declaration and rebuild the project, it still won't work.
Usually, whenever you create a class, the namespace declaration will also be included, but in this case there is no namespace included. If I am going to add a namespace it will not have any errors but I can't still access the other class.
I hope you can help me with this. Thanks.
Jun 27, 2017 01:00 PM|Mikesdotnetting|LINK
In the main VS menu, click on Project -> Properties to see the default namespace. Note: if you don't have a "Project" option in the menu, but you have a "Website" option, then you have created a Website project instead of
a web application project. You need to convert that to a web application project (or start over) if you want to use MVC. Website projects do not support MVC, They only support Web forms and Web Pages applications.
Usually, whenever you create a class, the namespace declaration will also be included
It's usually the default namespace concatenated to the folder name that the class is in. If the class is placed in a hierarchy of folders, you will see that as the namespace, so ifyour default namespace is WebApplication1, and you add a class file to a folder
called MyStuff in the Models folder, the generated namespace will be
If you want that class accessible to other classes in other namespaces, you add the following to the top of the other class file:
Or you can simply remove the folder names from the namespace in the class file you created so that the class resides in the default namespace:
That makes it accessible to all other classes in the application without having to add using directives.