【发布时间】:2013-12-18 14:18:15
【问题描述】:
我在将数据从数据库发送到控制器中的列表时遇到问题。我是 C# 和 MVC 的新手,所以任何帮助都会很有用!代码如下
public static List<FilterTree> GetAllUsers()
{
FilterTreeDBContext db = new FilterTreeDBContext();
var userList = new List<FilterTree>();
var device = new FilterTree();
//This is the line where I get the error
device.ID = from a in db.FilterTree select a.ID;
userList.Add(device);
return userList;
}
谢谢,节日快乐!! :)
【问题讨论】:
-
问题官有什么问题?
-
FilterTree 是您的数据库集。因此,从您的查询中,您将获得一个整数列表。 FilterTree 中实例变量 ID 的类型是什么?我想从你得到的错误中可以明显看出它是 int 的。您正在尝试将列表 (Iqueryable
) 存储到 int 字段。我希望此分析能帮助您解决问题。 -
感谢@AbhinavRanjan 的解释!
标签: c# database asp.net-mvc-4 controller