I want to search using PersalNumber or IdNumber and it gave me an error that says:
No overload for method 'Where' takes 2 arguments
I have schema consisting of PersalNumber and IdNumber
- PersalNumber stores a work number
- IdNumber stores numbers of passport or driving license etc
- Teachers is a table name
Below is the code I use for searching both the fields.
public ActionResult PopulateResult(string search)
{
return View(db.teachers.Where(x=>x.PersalNumber.Contains(search), s=>s.IdNumber.Contains(search)).ToList());
}
I want to know is there anything I am doing wrong here?
CodePudding user response:
You should adjust your condition like below
db.teachers.Where(x => x.PersalNumber.Contains(search) ||
x.IdNumber.Contains(search)).ToList();
CodePudding user response:
You need to use the || (or) operator between the two conditions.
return View(db.teachers.Where(x=>x.PersalNumber.Contains(search) ||
x.IdNumber.Contains(search)).ToList())
and you should make the comparison using the x argument not this undefined s
Note, this should work correctly if both PersonalNumber and IdNumber are strings.