使用数据列表查询视图

时间:2012-10-30 18:31:25

标签: c# asp.net-mvc linq

如何使用列表中的数据查询视图?

例如:下面,我有变量“data”,我将所有id从视图存储到列表中。我想查询第二个视图“vwStatus”,以便返回列表中显示状态的所有行(数据)

类似的东西:

public ActionResult Index(string id)
{
    var data = (from p in db.vwdb.Where(p => p.ID == id)
                 group p by p.status into g select g.Key).ToList();

    ViewData.Model = db.vwStatus.Where(p => p.Status == data);           

    return View();
}

希望我说清楚。

1 个答案:

答案 0 :(得分:1)

你可以这样做:

var data = (from p in db.vwdb.Where(p => p.ID == id)
                 group p by p.status into g select g.Key).ToList();

//Here you'll get the data you want from the database:
ViewData.Model = db.vwStatus.Where(vw => data.Contains(vw.Id));

return View();

这应该可以正常工作。

问候。