根据复选框选择用户

时间:2013-01-11 12:56:49

标签: asp.net-mvc

我有一个显示有关数据库中所有用户的详细信息的视图,我需要能够过滤此信息并仅显示管理员选择的用户。

目前控制器看起来像这样 -

public ViewResult Index()
    {
        var trs = db.TRS
            .Include(t => t.User);
        return View(trs.ToList());
    }

但我需要将此查询更改为仅包括所选用户。我已经改变了控制器 -

public ViewResult Index(FormCollection form)
    {

        string[] UserIDs = form["TRSIDs"].Split(',');

        var trs = db.TRS
            .Include(t => t.User);
        return View(trs.ToList());

    }

现在我有一个包含所有USERID的数组,是否可以更改查询以使用这些USERID,以便发送的列表只包含所选用户?

1 个答案:

答案 0 :(得分:1)

你想要这样的东西吗?

string[] UserIDs = form["TRSIDs"].Split(',');
//if userIds are int, you should type conversation from string array to int array
var trs = db.TRS.Where(g => UserIDs.Contains(g.User.UserId)).ToList();