public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } public string Description { get; set; } public string ImageUrl { get; set; }
public string SearchString { get; set; }
public int? MinPrice { get; set; }
public int? MaxPrice { get; set; }
}
public IActionResult Index(string searchString, int? minPrice, int? maxPrice) { var products = from p in _context.Products select p;
if (!string.IsNullOrEmpty(searchString))
{
products = products.Where(p => p.Name.Contains(searchString) || p.Description.Contains(searchString));
}
if (minPrice != null)
{
products = products.Where(p => p.Price >= minPrice);
}
if (maxPrice != null)
{
products = products.Where(p => p.Price <= maxPrice);
}
return View(products.ToList());
}