I have written an application in ASP.NET MVC and have implemented a search bar. This search bar is enabled for multiple fields. The problem I am having is enabling the search for an ID field of type int. It seems like I need to only have string values in my search field. Is there a way to convert the ID field to string type so I can also be able to search for that?
Here is the code i'm using. It works for first name and last name, but not when I have the ID part enabled.
Any help is appreciated!
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.LastSortParm = sortOrder == "LastName" ? "LastDesc" : "LastName";
ViewBag.FirstSortParm = sortOrder == "FirstName" ? "FirstDesc" : "FirstName";
ViewBag.IDSortParm = sortOrder == "ID" ? "RVHDesc" : "ID";
if (!String.IsNullOrEmpty(searchString)) //creates the code for the search bar
{
doctors = doctors.Where(d => d.Last_Name.ToUpper().Contains(searchString.ToUpper()) //insert to upper or lower so that case is ignored
|| d.First_Name.ToUpper().Contains(searchString.ToUpper()));
|| d.RVH_ID_.ToUpper().Contains(searchString.ToUpper()));
}
}
d.RVH_ID_is an integer, then you will need to callToString()before theToUpper()or you will get an error about no such method exists for integer.;in your.Where()before the last line.ToUpperon a string containing an integer? Is lowercase1different from uppercase1? Am I getting that out of touch?