View:
-
- Title: "text" name="SearchString" />
- Description: "text" name="SearchString" />
- "submit" value="Filter" />
- public class Product
- {
- public int Id { get; set; }
- public string Title { get; set; }
- public int Price { get; set; }
- [Display(Name = "Product description")]
- public string ProductDescription { get; set; }
- public int Stock { get; set; }
- }
Controller:
- public async Task
Index(string searchString, string description) - {
- var store = from m in _context.Products
- select m;
- if (!String.IsNullOrEmpty(searchString))
- {
- store = store.Where(s => s.Title.Contains(searchString));
- }
- if (!String.IsNullOrEmpty(description))
- {
- store = store.Where(s => s.ProductDescription.Contains(description));
- }
- return View(await store.ToListAsync());
- }

Sachin SinghRank #66 · 26.2K reputationPosted Feb 28, 2021, 3:06 AM EST
osyris zosarRank #6,574 · 262 reputationPosted Feb 28, 2021, 1:24 PM EST
its basicly a simple search on a E-commerce webpage
so it could be that the user only uses one field or all of them
Sachin SinghRank #66 · 26.2K reputationPosted Feb 28, 2021, 1:26 PM EST
osyris zosarRank #6,574 · 262 reputationPosted Feb 28, 2021, 1:31 PM EST
price, brand,name,delivery,Instock,popular,newProducts,outofstock. etc
that would be a very long code because you will have to create
a "else if statement" for every possible combination.
I dont think that would be a good solution
Kiran MohantyRank #821 · 2.8K reputationPosted Mar 1, 2021, 8:38 AM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Feb 28, 2021, 2:23 AM EST