CS0176编译器错误。这是什么意思,我该如何解决 [英] CS0176 Compiler error. What does it mean an how do I solve it
问题描述
我正在尝试使用ASP.NET MVC中的Linq从我的数据库中检索数据。但是当我在另一个类中调用该方法时,我得到了编译器错误代码CS0176:无法使用实例引用访问成员;而是使用类型名称来限定它。
Im trying to retrieve data from my database with Linq in ASP.NET MVC. but when I call the method in a different class, I get the compiler error code CS0176:"Member cannot be accessed with an instance reference; qualify it with a type name instead".
我如何调用该方法:
public JsonResult RetrieveDataTable()
{
DatabaseHandler.DatabaseHandler dataName = new DatabaseHandler.DatabaseHandler();
var dataListAssets = dataName.GetDisciplines();
return Json(dataListAssets, JsonRequestBehavior.AllowGet);
//return null;
}
该方法的外观:
public static List<DisciplineVM2> GetDisciplines()
{
using (var db = new SPIESimpel_DEVEntities())
{
return db.tbl_Disciplines
.Select((x) => new DisciplineVM2() { ID = x.ID, Name = x.Name })
.ToList();
}
}
有人看错了吗,可以帮助我解决这个问题有问题吗?
Does someone see whats wrong and can help me solve this problem?
预先感谢
推荐答案
这意味着您尝试从对象实例访问静态方法 GetDisciplines
。您应该改用类名来访问它。
It means that you are trying to access a static method GetDisciplines
from an object instance. You should instead access it using the class name.
在您的情况下,它将是:
In your case, it would be:
var dataListAssets = DatabaseHandler.DatabaseHandler.GetDisciplines();
这篇关于CS0176编译器错误。这是什么意思,我该如何解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!