ToString() inside where method

I have come with a solution. It might not be the best solution, but atleast it work as I want it to. I used this:

public async Task<ViewResult> Index(string searchString)
{
    var products = from p in _db.Products
    select p;
    
    if (!string.IsNullOrEmpty(searchString))
    {
        products = products.Where(p => p.Name.ToLower().Contains(searchString) || 
        (""+p.Id).Contains(searchString));
    }
   
    return View(products);
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top