在控制器中使用带有LINQ的ViewBag和SelectList在WHERE子句中添加AND(ASP.Net MVC)

时间:2016-09-25 13:42:42

标签: asp.net-mvc linq viewbag

如何在WHERE中使用ViewBag在当前LINQ中添加第二个Controller子句('AND')?谢谢!

ViewBag.Subjects = new SelectList(_odb.SUBJ_MSTR.
                   Where(o => o.TYPE== "4").OrderBy(o => o.SUBJ_NAME), "SUBJ_ID", "SUBJ_VAL");

1 个答案:

答案 0 :(得分:1)

您可以像&&这样添加WHERE

ViewBag.Subjects = new SelectList(_odb.SUBJ_MSTR.
                   Where(o => o.TYPE== "4" && o.TYPE=="5").OrderBy(o => o.SUBJ_NAME), "SUBJ_ID", "SUBJ_VAL");