2

I'm trying to add a controller in my ASP.NET MVC project.

I am using Entity Framework Code First (5.0), and when I right-click the Controllers folder in my project and selecting Add Controller:

enter image description here

After selecting MVC controller with read/write actions and views, using Entity Framework and other settings, I get this message:

There was an error generating '{0}'. Try rebuilding your project.

enter image description here

Update

Seems that the special constructor I added to the DbContext caused the problem. After commenting out the constructor, it's working back again, however this message appeared:

enter image description here

Anyway I checked the activity log and found no info regarding that issue or any record at the occurrence timeline, should you know what this is all about, please comment on.

6
  • Show me your scree to add Controller with Selection. Commented Apr 16, 2013 at 11:34
  • There you go, uploaded. Commented Apr 16, 2013 at 11:41
  • Try to Rebuild your project before Creating a controller. Commented Apr 16, 2013 at 11:44
  • Think I'd bother posting a question with screenshots before doing that? Commented Apr 16, 2013 at 12:15
  • 1
    @MattSull87 sounds like a good idea, anyway, I got a workaround for my question. Commented Apr 16, 2013 at 13:00

4 Answers 4

1

Seems that the special constructor I added to the DbContext caused the problem. After commenting out the constructor and re-compiling, it's working back again.

Perhaps I should wrap the constructor contents in a conditional statement that is skipped at design-time, meanwhile commenting-out is enough for me.

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

Comments

1

"Build the application before going on to the next step. If you don't build the application, you'll get an error adding a controller." "If you get an error, you probably didn't build the application before starting adding the controller." You must run project, probability. http://www.asp.net/mvc/overview/getting-started/introduction/accessing-your-models-data-from-a-controller

Comments

0

Just have an empty DbContext subclass when adding the controller. Then it will work fine for you...

1 Comment

But I will not be able to add the models used by the desired DbContext. Look at this answer.
0

If you are on Windows OS press CTRL + SHIFT + B to build the application then try again to add Controller

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.