Experts. I want to search the 'Name' field in my IList...but it is always case sensitive.How to search without case sensitive? Below are my codes:
Model:
public IList<Student> Search(IList<Student> list, string keyword)
{
return list.Where(e => e.Name.Contains(keyword)).ToList();
}
Class:
public class Student
{
public string Name {get;set;}
public string MatricNo {get;set;}
public string Gender {get;set;}
}
Controller:
IList<Student> list = new List<Student>();
Student students1 = new Student();
students1.Name = "Mike";
students1.MatricNo = "12345";
students1.Gender = "Male";
list.Add(students1);
Student students2 = new Student();
students2.Name = "Steve";
students2.MatricNo = "12345";
students2.Gender = "Male";
list.Add(students2);
Student students3 = new Student();
students3.Name = "Jane";
students3.MatricNo = "12345";
students3.Gender = "Male";
list.Add(students3);
string keyword = "mik"; //Example of search keyword
list = _searchModel.Search(list, keyword);
I want the list the return student named Mike, but it doesn't return. Instead it will return only if the keyword = "Mik". How to do the searching without case sensitive when keyword = "mik"? Please note that keyword can be a substring of 'Name' of student.