Firstly you should verify that your frmHostName
and frmOS
variables actually have values. Given your action declaration it doesn't look correct to me but if you could post the URL that is triggering a call to the action that would help.
For the query itself I prefer to break it up so it is easier to adjust later.
var query = serverContext.Servers.AsEnumerable();
if (!String.IsNullOrEmpty(frmHostName))
query = query.Where(x => x.HostName.Contains(frmHostName);
if (!String.IsNullOrEmpty(frmOS))
query = query.Where(x => x.OS.Contains(frmOS);
var servers = query.ToList();
return View(server);
Your where condition is looking for a contains so if frmOS
is win
then it would match windows
, onewin
and onewindow
. Make sure that is what you want.
It isn't clear here but it looks like you're using EF. Therefore also ensure your DB is case insensitive otherwise it won't match the strings either.