创建新的控制器

编程入门 行业动态 更新时间:2024-10-23 13:36:16
本文介绍了创建新的控制器 - 错误运行所选代码生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Visual Studio Express 2013 for Web(特别是版本12.0.21005.1 REL)。这是我使用VS2013的第一个项目,我一直在使用VS2012直到这一点。

I am using Visual Studio Express 2013 for Web (specifically version 12.0.21005.1 REL). This is my first project using VS2013, I've been using VS2012 up until this point.

我正在尝试在我的asp MVC应用程序中创建一个新的控制器。我正在使用代码优先的实体框架5(.NET 4.5)。我想让Visual Studio为我创建一个模板(你知道一个控制器,具有读/写/删除等视图,而不是从头写自己的代码)。

I am attempting to create a new controller in my asp MVC application. I am using Entity Framework 5 with code first (.NET 4.5). I want Visual Studio to create the template for me (you know, a controller with views to read/write/delete etc, rather than write the code myself from scratch).

但是,每次尝试创建控制器时,都会收到以下错误消息:

However, every time I try to create the controller I get the following error message:

在VS中有某种错误2013?我不知道这是什么意思,重新启动VS2013没有帮助。

Is there some sort of bug in VS 2013? I can't figure out what this means, and restarting VS2013 does not help.

这里是血腥细节....实际上这是非常简单的,因为这是一个新的项目,迄今为止写的代码很少。

Here are the gory details.... actually it is all very simple since this is a new project with very little code written so far.

我的模型:

namespace ProfessionalSite.Models { public class EntityModels { public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public virtual ICollection<Enrollment> Enrollments { get; set; } } public class Enrollment { public int ID { get; set; } public string EnrollmentName { get; set; } public string Credits { get; set; } } // Create the class that inherits from DbContext // The name of this class is also used as the connection string in web.config public class EFDbContext : DbContext { public DbSet<Student> Students { get; set; } public DbSet<Enrollment> Enrollments { get; set; } } } }

在我的网页。配置文件我有以下

And in my web.config file I have the following

<add name="EFDbContext" connectionString="Data Source=JONSNA\SQLEXP2012WT;Initial Catalog=ProfessionalSiteDb; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>

在标签内。

现在时间创建一个控制器。我右键单击解决方案资源管理器中的控制器,然后选择添加新的控制器。

Now time to create a controller. I right click on Controllers in the Solution Explorer, and choose to Add a new Controller.

然后

当我点击添加我得到

我不知道如何摆脱这个错误。我想作为一种解决方法,我可以自己键入代码,但我想知道这是一个错误或我做错了。在VS2012中,这只是工作...

I cant figure out how to get rid of this error. I guess as a workaround I can just type the code myself, but I'd like to know if this is a bug or something I have done wrong. In VS2012 this just worked...

我很感激任何帮助或指针。谢谢。

I'd appreciate any help or pointers. Thanks.

推荐答案

您不需要 EntityModels 以下:

namespace ProfessionalSite.Models { public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public virtual ICollection<Enrollment> Enrollments { get; set; } } public class Enrollment { public int ID { get; set; } public string EnrollmentName { get; set; } public string Credits { get; set; } } // Create the class that inherits from DbContext // The name of this class is also used as the connection string in web.config public class EFDbContext : DbContext { public DbSet<Student> Students { get; set; } public DbSet<Enrollment> Enrollments { get; set; } } }

然后当您创建控制器时,只需选择学生或注册为Model类。

Then when you create a controller, just select the Student or Enrollment for the Model class.

更多推荐

创建新的控制器

本文发布于:2023-11-17 00:05:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!