2

In my test MVC web application, I've created custom class, which retrieves data from database. I have created also another folder in MVC app called Data and i have placed that data class in this folder. When i want to use this class from Controller and when importing with:

using TestMvcApp.Data;

i get an error:

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

Where can be the problem? Why it cannot find my class? I have tried a lot of things like placing that class in controller folder, but nothing helped yet. I created my test MVC app according to this article Using MvcContrib Grid in ASP.NET MVC Project Thanks for tips and answers.

EDIT: Name of my class is "ProductDB" and i have specified the namespace in it. I imported that class into project, than i created DATA folder, then i placed that class in there and finally i have changed its namespace name to TestMvcApp.Data! That class is from my another project.

0

4 Answers 4

4

I don't know why, but in my case when I added the custom class, Visual Studio 2013 didn't mark it to compile. Instead, it was marked as "Content".

I got to know it because I edited the .csproj and my class was placed just as "Include". I changed it to "Compile" and voilá, it worked!

You may use the "Build Action" class's file property in the Properties Window.

Sign up to request clarification or add additional context in comments.

2 Comments

Same for me (VS2012, and this happened just for one of many cs files created in the same way)
This happened to me when I copied a class file from another project.
2

Did you create the class before or after you put it in the "Data" folder? If it was before, does it still just belong to the TestMvcApp namespace, or did you change its namespace to be TestMvcApp.Data? If not, you need to either change the namespace the class is in or change the using statement.

4 Comments

hi, thx for answer, i imported that class into project, than i created DATA folder, then i placed that class in there and finally i have changed its namespace name to TestMvcApp.Data! That class is from my another project.
Maybe try posting a portion of the code for the class as well as for the controller so we can see the declarations and the using statement. Just like @Cpfohl said, it's difficult to give a lot of guidance without more info.
i dont know why but when i created in Data Folder ProductDB class manually, everything is ok, so i copied only the code of that class and problem is solved. But I am still wondering why it was not recognizing imported class, weird.
Who knows - sometimes you think you've done everything right but you missed some small thing - happens to me all the time. Glad to hear it's working for you now.
1

If your class is called Data and your namespace is called TestMvcApp.Data I suspect that there is a naming collision.

1 Comment

sorry i forgot, name of my class is "ProductDB"
0

You must also set the namespace of the class to TestMvcApp.Data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.