Ok so I have searched for this and have found all kinds of things that seem to be the right answer but I cannot seem to get this working. I think I am close.
I have gotten this code to work in my controller which I call from Datatable serverside ajax:
var shares = await _dataService.GetAllAgencyShares();
if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortColumnDirection))
{
shares = shares.AsQueryable().OrderBy(sortColumn + " " + sortColumnDirection);
}
if (!string.IsNullOrEmpty(searchValue))
{
shares = shares.Where(m => m.FirstName == searchValue
|| m.LastName == searchValue
|| m.AgencyName == searchValue
|| m.FormId.ToString() == searchValue);
}
recordsTotal = shares.Count();
var data = shares.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data };
return Ok(jsonData);
The problem is I would like the search part
if (!string.IsNullOrEmpty(searchValue))
{
shares = shares.Where(m => m.FirstName == searchValue
|| m.LastName == searchValue
|| m.AgencyName == searchValue
|| m.FormId.ToString() == searchValue);
}
recordsTotal = shares.Count();
var data = shares.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal =
recordsTotal, data = data };
return Ok(jsonData);
to find anything "like" searchValue. Currently this finds exact matches.
I have tried using Contains but I believe that to be boolean. Most things I found are using EF and use IQueryable--I am not using EF. I have tried to cast IEnumerable as Queryable and nothing seems to work.
How exactly did you use .Contains()
?
It works fine if implemented like this;
shares = shares.Where(m => m.FirstName.Contains(searchValue)
|| m.LastName.Contains(searchValue)
|| m.AgencyName.Contains(searchValue)
|| m.FormId.ToString().Contains(searchValue));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.