如何使用Visual Studio 2013和Entity Framework将控制器添加到ASP.NET MVC?

时间:2023-01-27 15:13:21

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:

我在Visual Studio 2013中使用ASP.NET MVC 5.0和Entity Framework 6.0添加控制器时收到错误。我已经添加了一些控制器并生成了视图但是在添加了datatables包之后,我遇到了这种类型的错误:

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?

我已经清理并重建了该项目,但它仍然无法正常工作。有一个名为StudentClass的表,我想使用Entity Framework为该表添加控制器。如何成功生成控制器?

2 个解决方案

#1


3  

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.

如果您收到错误消息“获取类型时出错...”,请确保在添加类后构建了Visual Studio项目。脚手架使用反射来找到类。

#2


0  

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

尝试添加控制器,右键单击控制器模板,然后:添加 - >新建脚手架项...

如何使用Visual Studio 2013和Entity Framework将控制器添加到ASP.NET MVC?

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:

选择那个EF。然后用您的Model类(在您的情况下为StudentClass),数据上下文类和新Controller的名称填充Add controller表单:

如何使用Visual Studio 2013和Entity Framework将控制器添加到ASP.NET MVC?

#1


3  

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.

如果您收到错误消息“获取类型时出错...”,请确保在添加类后构建了Visual Studio项目。脚手架使用反射来找到类。

#2


0  

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

尝试添加控制器,右键单击控制器模板,然后:添加 - >新建脚手架项...

如何使用Visual Studio 2013和Entity Framework将控制器添加到ASP.NET MVC?

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:

选择那个EF。然后用您的Model类(在您的情况下为StudentClass),数据上下文类和新Controller的名称填充Add controller表单:

如何使用Visual Studio 2013和Entity Framework将控制器添加到ASP.NET MVC?