如何解析“无法检索MVCApplication.Models.StudentList的元数据”。在c#asp.net mvc中添加控制器期间? [英] How to resolve "Unable To retrieve metadata for MVCApplication.Models.StudentList." during add controller in c# asp.net mvc?

查看:48
本文介绍了如何解析“无法检索MVCApplication.Models.StudentList的元数据”。在c#asp.net mvc中添加控制器期间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何解决无法检索MVCApplication.Models.StudentList的元数据。在配置中找不到指定的命名连接,而不是要与EntiyClient提供程序一起使用,还是无效在c#asp.net mvc 4中添加控制器期间?



我无法在我的应用程序中添加控制器。



i我正在使用空MVC应用程序,我没有选择互联网应用程序。



请帮助我。



提前致谢。



Ankit Agarwal

软件工程师

Hello,

How to resolve "Unable To retrieve metadata for MVCApplication.Models.StudentList.The specified named connection is either not found in the configuration, not intended to be used with the EntiyClient provider, or not valid" during add controller in c# asp.net mvc 4?

I cant add controller in my application.

i am using Empty MVC Application, i have not choose internet application.

Please help me.

Thanks in advance.

Ankit Agarwal
Software Engineer

推荐答案

这是因为您需要为将继承自DbContext的数据创建一个上下文对象,并将任何所需的连接详细信息添加到您的web.config中。或者,您可以将控制器创建为类而使用非EF数据访问。



如果您想使用EF:

This is because you need to create a context object for your data that will inherit from DbContext and add any needed connection details into your web.config. Alternatively, you can create a controller as a class instead and use non-EF data access.

If you want to use EF:
public class StudentContext : DbContext
{
    DbSet<student> { get; set; }
}





然后在控制器创建中,选择Student作为您的Model和StudentContext作为您的上下文。



或者,如果您想使用从其填充的任何地方填充的StudentList,您可以创建新课程并且:





Then in the controller creation, select Student as your Model and StudentContext as your context.

Alternatively, if you want to use StudentList, populated from wherever it's populated from, you can create new class and:

public class StudentController : Controller
{

    public StudentContext()
    {
        var list = new StudentList(); // Assuming this is a self-initialized object
    }

    public ActionResult ListStudents()
    {
        return View(list);
    }

    //Other data access methods here
}





等等。



编辑:

我也想引导你学习资源在7天内逐步学习MVC(模型视图控制器) - 第1天 [ ^ ]


你应该在下面添加以下代码型号:

public int ID {get;组; }



//以下给出一个例子:



公共类示例



{



public int ID {get;组; } //此代码ID有助于检索元数据..并连接到数据库



public string Name {get;设置;}

}

//或尝试使用public int id {get;组; }

//或尝试公共字符串ID {get;设定}

//或尝试公共字符串id {get;设定}

//你还应该正确地提到

connectionStrings。
You should add the below code in the model :
public int ID { get; set; }

// below given an example :

public class Example

{

public int ID { get; set; } // this code ID helps to retrieve meta data.. And connecting to database

public string Name { get; set;}
}
// or try public int id { get; set; }
// or try public string ID { get ; set ; }
// or try public string id { get ; set ; }
// you should also mention
connectionStrings properly.


这篇关于如何解析“无法检索MVCApplication.Models.StudentList的元数据”。在c#asp.net mvc中添加控制器期间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆