查询学生
控制器
#region 查询学生
public ActionResult SelectStudent(LayuiTablePage layuiTablePage, int AcademeID, int GradeID, int ClassID, string StudentNumber)// 查询学生
{
var Student = (from tbStudent in ChongQing.PW_Student
join tbAcademe in ChongQing.SYS_Academe
on tbStudent.AcademeID equals tbAcademe.AcademeID
join tbSpecialty in ChongQing.SYS_Specialty
on tbStudent.SpecialtyID equals tbSpecialty.SpecialtyID
join tbGrade in ChongQing.SYS_Grade on tbStudent.GradeID equals tbGrade.GradeID
join tbClass in ChongQing.SYS_Class on tbStudent.ClassID equals tbClass.ClassID
join tbUser in ChongQing.PW_User on tbStudent.UserID equals tbUser.UserID
select new Vo.Student
{
// VO是value object的缩写
// 作用:它是为了页面显示取值方便。所以将数据封装为一个对象。这对象也就是我们说的VO
// V0则主要用于逻辑层和表示层之间数据处理封装
// 给Student的每个属性赋值
StudentID = tbStudent.StudentID,// 学生ID
StudentNumber = tbStudent.StudentNumber,// 学号
StudentName = tbStudent.StudentName,// 姓名
StudentIDNumber = tbStudent.StudentIDNumber,// 身份证号
StudentSex = tbStudent.StudentSex,// 性别
Academe = tbAcademe.AcademeName,// 学院
Specialty = tbSpecialty.SpecialtyName,// 专业
Grade = tbGrade.GradeName,// 年级
Class = tbClass.ClassName,// 班级
UserName = tbUser.UserName,// 账号
AcademeID = tbStudent.AcademeID,// 学院ID
GradeID = tbStudent.GradeID,// 年级ID
ClassID = tbStudent.ClassID// 班级ID
}).ToList();
// 条件查询
if (AcademeID > 0)// 学院ID
{
Student = Student.Where(m => m.AcademeID == AcademeID).ToList();
}
if (GradeID > 0)// 年级ID
{
Student = Student.Where(m => m.GradeID == GradeID).ToList();
}
if (ClassID > 0)// 班级ID
{
Student = Student.Where(m => m.ClassID == ClassID).ToList();
}
if (!string.IsNullOrEmpty(StudentNumber))// 学号
{
Student = Student.Where(m => m.StudentNumber.Contains(StudentNumber.Trim())).ToList();
}
int total = Student.Count();// 总条数
List<Vo.Student> ListStudent = Student.OrderBy(m => m.StudentID)
.Skip(layuiTablePage.GetStartIndex())
.Take(layuiTablePage.limit).ToList();
LayuiTableData<Vo.Student> layuiTableData = new LayuiTableData<Vo.Student>();
layuiTableData.count = total;
layuiTableData.data = ListStudent;
return Json(layuiTableData, JsonRequestBehavior.AllowGet);// 查询学生
}
#endregion
JavaScript