asp.net mvc中按ID过滤

问题描述 投票:0回答:1

[当我使用条件不在表或页面中显示数据时,筛选器数据出现问题。

我有三个表GroupsSubgroups >>,Students

首先选择小组,然后选择子小组,然后从子小组的学生表中显示

这是我的控制器:

public ActionResult Index(int? id)
{
    var students = db.Students.AsQueryable()
        .Include(s => s.Groups)
        .Include(s => s.Subgroups)
        .Include(s => s.Schedules)
        .Include(s => s.Teachers);

    if (id != null)
    {
        students = students
            .Where(s => s.SubgroupId == id).Where(s => s.GroupId == id);
    }

    ViewBag.result = students;
    return View(students.ToList());
}

当我删除groupId

时,显示数据,但组数据未过滤,因此所有组显示。

我不知道怎么了

谢谢

我在使用where条件的情况下数据未显示在表或页面中时,过滤器数据出现问题。我有三个表Groups,Subgroups,Students首先我选择组,然后再选择子组...

asp.net-mvc filter
1个回答
0
投票

您过滤了两次,请尝试过滤一次:

© www.soinside.com 2019 - 2024. All rights reserved.