How do I add a controller to ASP.NET MVC with Visual Studio 2013 and Entity Framework?

爷,独闯天下 提交于 2019-12-23 10:22:37

问题


I am getting an error when I add a controller in Visual Studio 2013 with ASP.NET MVC 5.0 and Entity Framework 6.0. I have already added a few controllers and generated views but after I added the datatables package, I am getting this type of error:

Error 

"There was an error running the selected code generator"

"There was an error getting the type 'project.classes.StudentClass' Try rebuilding the project"

I have cleaned and rebuilt the project but it still isn't working. There is a table named StudentClass and I want to add the controller for that Table using Entity Framework. How can I generate the controller successfully?


回答1:


If you get an error message that says "There was an error getting the type...", make sure that you built the Visual Studio project after you added the class. The scaffolding uses reflection to find the class.




回答2:


Try to add controller with right-click on controllers template and then: Add -> New Scaffolded Item ...

Select that one with EF. Then fill Add controller form with your Model class (StudentClass in your case), Data context class and name of the new Controller:



来源:https://stackoverflow.com/questions/23272906/how-do-i-add-a-controller-to-asp-net-mvc-with-visual-studio-2013-and-entity-fram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!