Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 无法在MVC中检索元数据_Asp.net Mvc_Controller - Fatal编程技术网

Asp.net mvc 无法在MVC中检索元数据

Asp.net mvc 无法在MVC中检索元数据,asp.net-mvc,controller,Asp.net Mvc,Controller,我的应用程序运行正常。现在我添加了这个模型LogOn.cs public class LogOn { public int Id { get; set; } public string UserName { get; set; } public string Password { get; set; } } public class LogOnContext : DbContext { public DbSet<LogOn> LogOns { g

我的应用程序运行正常。现在我添加了这个模型LogOn.cs

 public class LogOn
{

    public int Id { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }

}
public class LogOnContext : DbContext
{
    public DbSet<LogOn> LogOns { get; set; }
}
我建立了这个应用程序,现在想添加控制器,它看起来像这样

当我按下“添加”按钮时,我得到了这个错误

这是什么意思?我错过了什么?我找到了这个。这可能会解决您的问题:

在根web.config文件中,更改
<connectionStrings>
<add name="YourConnectionString" ...other code goes here...  </connectionStrings>
致:

另外,在更改连接字符串名称后,必须重新生成连接字符串。

请尝试此操作

 public class LogOn
 {
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }

 }
PS:我通常会创建一个空的控制器,然后自己编写代码

 public class LogOn
 {
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }

 }